Ding sound on pressing Enter - c++

i used to write this code
if(Edit1->Text != "" && Key == VK_RETURN){
Edit1->Text = Edit1->Text.Trim();
Edit2->SetFocus();
}
and it works just fine, till I used C++ builder Xe6. the ding sound come up each time I press Enter button.
any help?

The beep sound is the default behavior on your IDE. Try:
if(Edit1->Text != "" && Key == VK_RETURN){
Key=0;
Edit1->Text = Edit1->Text.Trim();
Edit2->SetFocus();
}
Alternate solution:
How to turn off beeping when pressing ENTER on a single-line EDIT control under Windows CE?

Related

How can I make Qt recognize a sequence of keys?

In my current application, I need to make QT close a window by pressing Shift + Eesc or by pressing Esc 3x.
First, I tried Shift + Esc, it went this way
if ((event->key() == Qt::Key_Escape) && (event->key() == Qt::Key_Shift))
{
cout << "test" << endl;
on_close_x_button_clicked();
}
But for some reason, it just doesn't work. I googled it and found something about a QKeySequence but I didn't find any example of how to do it properly. I tried some ways with no success like:
if ((event->key() == Qt::QKeySequence(Qt::Key_Escape + Qt::Key_Shift)))
{
cout << "teste" << endl;
on_close_x_button_clicked();
}
}
But again, no dice. Can someone point me how to proper implement this functionality?
I also could not find anything that allowed me to create an event based on pressing Escape key 3x. Can someone, please, also teach me how to do it?
I also tried using Shortcuts, and it went like this:
LinAdvancedTestWidget::LinAdvancedTestWidget(QWidget *parent,
QObject *event_filter,
SystemEvent *event, int dpi)
: AdvancedTestWidget(parent, event_filter, event) {
(void)dpi;
KeyShiftEsc = new QShortcut(this);
KeyShiftEsc->setKey(Qt::Key_Shift + Qt::Key_Escape);
connect(KeyShiftEsc, SIGNAL(activated()), this, SLOT(slotShortcutShiftEsc()));
}
void LinAdvancedTestWidget::slotShortcutShiftEsc()
{
cout << "Escape LinAdvancedTestWidget" << endl;
on_close_x_button_clicked();
}
But it again, also does not work :/
Shift is a modifier, not a key, as you seem to compare. You would need to write something like this:
if ((event->key() == Qt::Key_Escape) && (event->modifiers() & Qt::Key_Shift))
{
...
}
Also, it is better if you use the QWidget::addAction(...) method as:
QAction *action = new QAction("my action", "Shift+Esc");
myWidget->addAction(action);
You can also set multiple shortcuts on an action:
action->setShorcuts({"Shift+Esc", QKeySequence(Qt::Key_Esc, Qt::Key_Esc, Qt::Key_Esc)});

Setting a default path in getOpenFileName (X++)

I was wondering how I can set a default path for a Open File dialog in X++.
The situation is this: In Microsoft Dynamics AX there's the form InventTable, which shows all data concerning our inventory.
On of the properties of every item is an image. These images are all stored in the same folder on our server. So when we press the button to set or change the image, I would like the dialog box to automatically go to this folder, so users don't have to go there themselves.
This is the code behind the Change Image-button so far:
void clicked()
{
FilenameFilter filter = ['Image Files','*.bmp;*.jpg;*.gif;*.jpeg'];
BinData binData = new BinData();
str extention, path, nameOfFile;
super();
imageFilePathName = WinAPI::getOpenFileName(element.hWnd(),filter, '', "#SYS53008", '','');
if (imageFilePathname && WinAPI::fileExists(imageFilePathName))
{
[path, nameOfFile, extention] = fileNameSplit(imageFilePathName);
if (extention == '.bmp' ||
extention == '.jpg' ||
extention == '.gif' ||
extention == '.jpeg')
{
binData.loadFile(imageFilePathName);
imageContainer = binData.getData();
inventTableImage.ADUImage = imageFilePathName;
element.saveImage();
element.showLogo();
}
else
{
throw error("#SYS89176");
}
}
}
I've read that I could set a default path in the getOpenFileName-method, but that doesn't seem to work.
The form itself has a method called filenameLookupInitialPath which returns just an empty string.
the default path parameter works fine for me in Ax 2012 RTM 3. Are you sure the code is being executed on the correct tier and the path is correct?
WinAPI::getOpenFileName(0, conNull(), #'C:\users\', '');

ESC key for back to main interface

I have a problem with using the ESC key for back action. At the same time I want to receive user input too, but if the user wants to go back, they just press ESC key to go back. I tried to use while... getch(), but the problem is if I press backspace, the character that the user enters is not deleted.
Here is my code frame I made:
int main(){
do{
/* here I make my main interface */
if (choice == "1"){
/* here I wan to make [ESC] key for back to main interface
Press only one time then back and the same time can input
data */
}
...
else if (choice == "X" || choice == "x"){
flag = false
}
else{
wrongchoice();
}
}while(flag = true)
}

Handling arrow key in cedit control of mfc

I'm making matlab-like command window using cedit control of mfc.
For example, after I input several commands, I want to display old command using an arrow key (specifically the up key).
I succeeded in displaying old commands, but failed to locate the cursor on the end of this command.
The reason seems that the arrow key was input one more time after I locate the cursor in the end of this command.
Here is detailed situation.
First I input command 'play'
and then Play!.. message pops up.
and in the next command prompt I hit '↑' key
and I succeded the old command 'play' streamed automatically,
However, my cursor go up to upper line.
# play
Play!.. | (← cursor located here..)
# play| (← I want to locate the cursor here, after hitting '↑' key)
This is my code:
class CEditCommand::CEdit
{
public:
virtual BOOL PreTranslateMessage(MSG* pMsg);
}
BOOL CEditCommand::PreTranslateMessage(MSG* pMsg)
{
if (pMsg->message == WM_KEYDOWN)
{
if (pMsg->wParam == VK_UP)
{
int nS = 0; nE =0;
GetSel(nS, nE);
int nLineIndex = LineIndex();
CString str = m_CommandHistory[m_nCommandIndex];
m_nCommandIndex--;
SetSel(nLineIndex, nE);
ReplaceSel(str);
SetSel(0, -1);
SetSel(-1, -1);
}
}
}
I don't know why '↑' key would be pushed again after executing PreTranslateMessage.
Does anyone have an idea about this?
Your edit control will still get the up-arrow message, so you will need to return TRUE in CEditCommand::PreTranslateMessage() for both WM_KEYDOWN and WM_KEYUP when pMsg->wParam == VK_UP

Global alt+space hotkey grabbing - weird keyboard focus behaviour

I'm grabbing Alt+Space global hotkey using xcb_grab_key, as follows:
xcb_key_symbols_t *keysyms = xcb_key_symbols_alloc(c);
xcb_keycode_t *keycodes = xcb_key_symbols_get_keycode(keysyms, XK_space), keycode;
// add bindings for all screens
xcb_screen_iterator_t iter;
iter = xcb_setup_roots_iterator (xcb_get_setup (c));
for (; iter.rem; xcb_screen_next (&iter)) {
int i = 0;
while(keycodes[i] != XCB_NO_SYMBOL) {
keycode = keycodes[i];
xcb_grab_key(c, true, iter.data->root, XCB_MOD_MASK_ANY, keycode, XCB_GRAB_MODE_SYNC, XCB_GRAB_MODE_SYNC);
i += 1;
}
}
Then in Qt's QAbstractNativeEventFilter subclass I process it and emit a Qt signal if key matches Alt+Space:
xcb_keycode_t *keycodes = xcb_key_symbols_get_keycode(keysyms, XK_space);
int i = 0;
bool found = false;
while(keycodes[i] != XCB_NO_SYMBOL) {
if(event->detail == keycodes[i]) {
if(event->state & GetModifier(c, keysyms, XK_Alt_L) || event->state & GetModifier(c, keysyms, XK_Alt_R)) {
xcb_allow_events(c, XCB_ALLOW_ASYNC_KEYBOARD, event->time);
emit gotHotKey();
found = true;
} else {
xcb_allow_events(c, XCB_ALLOW_REPLAY_KEYBOARD, event->time);
}
break;
}
i += 1;
}
if(found) return true;
(GetModifier is copied from VLC but I think this part doesn't matter since Alt-key is matched correctly)
The problem I'm having is that after show()ing main window when the hotkey is pressed, keyboard is most of the times1 not focused properly. I can type, but the cursor is not visible, input's border is not highlighted, and the shortcut Ctrl+Q for quitting desn't work. It can be worked around by moving the window, or pressing space - then focus is restored - cursor+border reappears and Ctrl+Q works. What might be causing this behaviour?
I'm using Qt 5.0.0 and xcb 1.8.1. Complete application can be downloaded for compiling from github.
1 it means sometimes the issue is not reproducible - focus is set correctly even for repeated window hide/shows, but then other times it happens multiple times in a row of hide/shows. It occurs more often than not overall.
(Edit: I've implemented a (very ugly...) workaround, so to reproduce the issue for the github project, the following code needs to be removed)
#ifndef WIN32
// Very ugly workaround for the problem described at http://stackoverflow.com/questions/14553810/
// (just show and hide a modal dialog box, which for some reason restores proper keyboard focus)
hackDialog.setGeometry(0, 0, 0, 0);
hackDialog.setModal(true);
hackDialog.show();
QTimer::singleShot(100, &hackDialog, SLOT(reject()));
#endif