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.
Related
I would like to know how to detect the keyboard adapter on Windows when using two keyboards, that a key eg. W was pressed on first or on the second keyboard.
Can anybody help me how to do it?
I would like to use a cheap solution for macros. I would plan to bind macros for entrie second keyboard, when somebody press key W (just for example), keybaord would type a world uint8_t.
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.
Is it possible to create a keyboard shortcut to switch between the monitor and portion selection of this wacom preferences window, via a c++ console program?
Sorry if this is poorly worded, I've had trouble trying to find the right words to search for ways to do it.
I think it should be possible, although a bit tedious. You should be able to use the Windows API, and try to EnumWindows/EnumDesktopWindows to identify the respective application Window, and its respective controls (which are also Windows).
You should identify the window title, and class ids, for the app window, and the checkbox button controls, then when you enumerate through all the desktop windows, you can identify the ones you are interested in.
Then you can use the SendMessage() API to send messages to the controls (Windows) of interest to manipulate them.
It's a bit tedious, but sounds possible.
An example of use here to get an idea:
http://www.cplusplus.com/forum/windows/25280/
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.
I'm trying to write a Keyboard class that can read in the keyboard buttons. I have looked at this link - http://www.daniweb.com/software-development/cpp/code/216732/reading-scan-codes-from-the-keyboard But as stated on there, it is not very accurate for all computers (I don't know if this is even true). Therefore, my question is whats the best method in implementing my keyboard class? This will be used for Windows
Many thanks
There are three ways to read keyboard input:
By reading input from a console window as described in your link. It's true that it's hard to get this to work correctly, for starters because it's reading ANSI characters and not Unicode characters, but there are other issues. Console input/output is kind of obscure, as is the documentation for it
By handling UI events associated with a normal window. In this case you would handle the WM_KEYDOWN message in a window procedure
By going deep into the Win32 API with functions like SetWindowsHookEx. In this case you don't even need a window (normal or console), and you can read keystrokes pressed in any application or in the desktop
It's hard to suggest which one to use without knowing how you intend to use this Keyboard class.