wxMenuItem accelerator specifications - c++

I'm trying to use some numpad button (like /, * and digits) as accelerators for wxMenuItem (C++, GTK), but they doesn't works.
If I specify just 2, only the ordinary 2 button will fire the event, not 2 on numpad with NumLock ON (while ASCII codes are the same). It's the same with / and * buttons.
I've tried to find some specifications for accelerators in wxWidgets docs, but unfortunately they are not complete (for example, it says I need to specify pgdn for PageDown key, but actually both PgDn and PageDown works good) and give no idea of using NumPad buttons.
Tried something like NumX for NumPadX buttons - it doesn't works too.
So, the questions are:
1) Is there any complete specification for accelerators in wxWidgets?
2) If not, can anyone suggest me how to use NumPad buttons as accelerators?

You're looking for WXK_NUMPAD2 (which is documented together with all the other key codes) and the corresponding menu accelerator string (which is unfortunately not documented) is KP_2.

Related

Windows API - registering a hotkey with multiple keys combination

So for example I can easily register a hotkey that is a combination of Shift, Alt (Mod keys) and Up arrow:
RegisterHotKey(NULL, TOP, MOD_SHIFT | MOD_ALT, VK_UP);
This works just fine but what I'm after is registering a hotkey with the same keys as above PLUS another normal key like Left arrow, so the combination would be Shift, Alt, Up arrow, Left arrow.
There isn't space in the function for another argument, and I tried doing a bitwise OR for the Up and Left arrow keys like
VK_UP | VK_LEFT
... but it's not working. If anyone encountered this problem before or knows how I proceed please help!
Windows hotkeys don't support multiple (non-modifiers) keys. You cannot bitwise OR multiple VK_* values, only MOD_* values can be combined.
If you desperately need this feature then you have to use a low-level keyboard hook and track the keys yourself. Hooking affects global system performance and should be avoided if possible.
If you decide to do this you have to remember that Windows users are not used to pressing hotkeys this way, only menus allow a somewhat similar pattern but you don't have to hold the Alt modifier to make those work. You must also remember to test your hook with StickyKeys and other accessibility features...

How to convert X11 KeyCode or KeySym to scan code

I need to get scan codes of keyboard buttons (or any other codes) in layout-independent way. More specific, let's say I have QEditText and catching keystrokes from it. Now I'm starting to press a single button, and when the layout is English it has keycode=X, then I'm switching layout to Russian (German, French, whatever) and keycode becomes Y - but the physical button is the same. So I need to know code of that physical button, how to do this?
I am not sure if you will be able to do this only from code itself by some qt/x11 methods, but there is a tool that helps in similar situations: xbindkeys. You can read more here:
https://unix.stackexchange.com/questions/91355/shortcut-keys-that-are-independent-to-keyboard-layout
If you can't use xbindkeys, you can still check its code and see how the author achieved this.

DirectX 11 input read methods

I'm writing an application now and i need to include inputs to this app. I'm confused now a bit. I heard about four options.
1. Basic windows messages system,
2. DirectInput8,
3. RawInput,
4. XInput.
I need to distinguish:
1. uppercase letters from lowercase letters,
2. arrows and special keys from other chars (i mean left arrow key is translated to % when usgin translate message and it's problem coz i need to dostingush them),
3. it would be good if it would be possible proceed data as messages.
Now, my question is: Which one of these four would you use to implement input? Maybe you have another good way to do this?
PS. I need to handle mouse and keyboard.
If you don't need joystick gamepad support plain window messages work for everything.
To read character data that will be displayed on screen like text being entered into an input box use WM_CHAR, WM_CHAR will return different codes for a and A.
For input keys like left/right arrows etc. you can use WM_KEYDOWN / WM_KEYUP.
Windows messages work well for mouse clicks too and for mouse position I prefer to use GetCursorPos and translate it into the client window coordinates.
For other input devices XInput is the prefered choice.

What is difference between hotkey, shortcut and accelerator key?

What is the difference about them?
In Qt, if I have a hotkey for QPushButton, I can make it by "Alt + ?", but if it's for qaction, I can press "?" only
In Windows, an accelerator key is application global; e.g. Alt+F4.
A shortcut key is part of the name of a menu item or button, where it can be underlined, and is available (without modifiers) when that menu item or button is directly available.
From Microsoft:
A hot key is a key combination that the user can press to perform an action quickly. For example, a user can create a hot key that activates a given window and brings it to the top of the z-order.
which seems to indicate that hot keys are system global.
To sum up:
shortcut key = no modifiers, local in menu or (for button) in window
accelerator key = typically with modifier, application global
hot key = apparently system global
I don't know about specific meanings in Qt; for that see the Qt documentation.
Alf's answer is correct for Windows applicability. Your terms you mention (hotkey/shortcut/accelerator) don't sound familiar from a pure Qt point of view.
In Qt you can elect to handle key sequences yourself or you can use Qt's own simplification method. Either way you must remember that Qt itself targets many platforms on which a key combination may or may not make sense. The classic Alt + F4 makes sense on a keyboard, but on a mobile device you don't have an Alt modifier or an F4 key. What you really want is a way of specifying a generic close the application shortcut. This problem is multiplied because the symbol may be available but the key sequence to reach it might be different on other keyboard layouts. This section of the documentation provides a good example.
Qt handles this with class QKeySequence. The very clever Qt developers have provided an easy way of defining common user actions and those actions will use key combinations that are default to the target platform. It does this using enum QKeySequence::StandardKey and in the close the application example, you could use this like so:
QAction exitAction;
exitAction.setShortcut(QKeySequence(QKeySequence::Quit));
This is all explained in the documentation. There are a two other modifiers (shortcutContext() and softKeyRole()) which can be applied to QActions which effect their application in more advanced ways.
You are also free to assign your own shortcuts using something like:
QAction helpAction(tr("&?"));
helpAction.setShortcut(QKeySequence(tr("ALT+?")));
The first line applies the (translated) text "?" to the action which will appear as its text on a menu or button. Note that the question mark symbol might not be the right symbol in all languages so the translate method allows a translator to assign a more appropriate symbol if required. The ampersand symbol means the character immediately after will be the short-cut key when the menu is active.
The second line assigns the (translated) shortcut of Alt + ? and in this example the Shift modifier will be handled by the platform if required. Again, the tr() method allows the translator to specify a more appropriate shortcut if available.
In response to teukkam's comment:
If you mean you simply want your button to be triggerable by a keystroke whether its modified by Alt or not then you could do something like:
QPushButton* yourButton; // assign this pointer yourself
yourButton->setText(tr("&Process"));
yourButton->setShortcut(tr("p"));
In this example, the ampersand in setText() does the same as the previous example, and the translate function is used in the same way.
The setShortcut() method just uses the letter "p" so should work now with or without the Alt modifier. A quick skim of the documentation suggests this will work with or without the Shift modifier as the letters in a key sequence are apparently case-insensitive.
Also, P would be a bad choice as its often assumed to be the print command.
A final note if you're defining hard coded short cuts, make sure they work on all your target platforms!
In Windows:
HotKey
Keyboard key or combination of keys that execute a command in a given context.
Shortcut
Multi-key HotKey with no menu navigation restrictions nor gui elements required.
AccessKey
Single key HotKey which command is to activate a visible command control
(requires gui element) that is captioned/labeled with the corresponding hotkey letter underscored.
Accelerator Keys
Multi-key HotKey which command is to activate a command control (requires gui element) regardless of its visibility.

Capturing keyboard input without focus on the programwindow

I am doing a VoIP client and I want to start/stop on WM_KEYDOWN and WM_KEYUP messages for a certain input, say K. When the main window has focus, this is np, but how do I enable it outside of the window? For example, if the window is not in focus and I'm just looking at the desktop or am in a videogame. How does one perform something like this? I am not sure where to begin.
Also -- I guess you somehow has to poll every input even outside the program, is that expensive?
win32 c++ btw
You need to install keyboard hooks: http://msdn.microsoft.com/en-us/library/ms644990(v=VS.85).aspx
This can be very troubling though for every running application if something steals its keyboard messages.
I don't think you want this - if I'm typing a document into Word and I hit K, I'm going to be very angry when your application pops up instead of a "k" appearing in my document.
Windows allows you to assign shortcut keys to an icon on the desktop, but it limits them to the function keys or to combinations containing both Alt and Ctrl. Right-click on a desktop icon and go to Properties, and look for the field marked "Shortcut key".