How to get modifier key event(alt+ctrl+shift), - winapi

If anyone is working on win32 API.Please have a look to below issue.
I have a requirement to call a function when modifier keys are pressed(alt+ctrl+shift) at same time in win32 programming.But I am not getting how to handle this event when modifiers keys are pressed at same time.
If someone have any idea please post it.

To get the status of key there is an API GetKeyState. With help of this you can check whether a key is down or up.
For example:
if (GetKeyState(VK_SHIFT)& 0x8000)
//Key is pressed
you can also check in combination like this:
if (GetKeyState(VK_SHIFT)& 0x8000 && GetKeyState(VK_CONTROL)& 0x8000)
//ctrl+shift key is pressed.

You should handle WM_KEYDOWN and WM_KEYUP messages, and track the state (up or down) for all of these keys: VK_SHIFT, VK_CONTROL, VK_MENU.

Related

What does combination of "Function Key + Insert key" actually do?

When I did it accidentally, it did like putting my windows machine to sleep
Is it what it does ?
Function key is generally linked with OS/computer functions, so a comnbination of it and another key is usually a shortcut to some system function, which in this case is sleep-mode.
In some computers, function+insert turns on numlock.
only fn does nothing, only insert pastes.
(Not an function key like f1, the fn key you see on your keyboard)

Apple script simulate key events

I want to know the key codes for all the function keys from F1-F12. From previous search queries I have found keycode 107 to turn brightness down by running this
echo "tell application \"System Events\"
key code 107
end tell" | osascript
And I'm guessing that simulates the F1 key but the weird thing is 113 turns the brightness up. I haven't been able to find key codes for any other Fn keys. Any help? Is there a nice table made for this where I can get the keycodes. In the end I want to be able to either directly perform the actions that these keys do or somehow simulate those actions. Anything would be fine.
Key code 107 is not the F1 code; it is a separate code for Brightness control. There is also one for Volume control, but it is broken. The key codes are in semi-random order and can not be predicted. The Function keys are:
F1=122, F2=120, F3=99, F4=118, F5=96, F6=97, F7=98, F8=100, F9=101, F10=109, F11=103, F12=111
You can find an exhaustive list of Key Codes here.

Determine if Control key was used to generate character in WM_CHAR

When receiving character input, is there a way to know whether the character code in wParam was generated as a result of the keyboard state we get back from GetKeyboardState()? For example, if you hit Ctrl+A then the character 'a' would not be a result of the control key but if you're using a Swedish keyboard and type Ctrl+Alt+7 the result would be {. In that case, is there any way of knowing that the keyboard state (Ctrl and Alt) were necessary to generate that character code?
(To be honest, as an English speaker who has really only ever used a US keyboard layout, I have no definite idea that this will work, but...) I believe that the VkKeyScan function (or VkKeyScanEx) might do what you want.
As input, it takes a character, not a scan code or a virtual key, so this is the wParam value that you get from WM_CHAR.
Its return is a value that provides both the virtual-key code (which I guess you can ignore) in the low-byte, and the (mis-named) "shift state" in the high-byte, which is actually a set of flags representing the qualifier keys needed to produce that character.
So if you get a WM_CHAR message and wanted to tell if the control key was needed in order to generate it, in theory you could do:
case WM_CHAR:
if (HIBYTE(VkKeyScan((TCHAR)wParam)) & 2) {
// control pressed!
}
break;
If you are only looking at the data provided by the WM_CHAR message, then no. You would likely have to look at the WM_KEY... messages to keep track of what the surrounding keystrokes where doing at the time, if Get(Async)KeyboardState() does not provide what you need.

Remap Capslock Key in Keymando?

Can you remap the CapsLock key in Keymando?
CapsLock is listed as an available key but when I try a test like:
map "<CapsLock-j>" { alert("CapsLock-j") }
... and hit Reload Config in the Keymando menu, I get an error dialog that says:
Error Parsing Keymando Config File
undefined method `ctrl' for nil:NilClass
Is there perhaps an abbreviation of CapsLock? For example, in the available keys, the Control key is just listed as Control but in the example code it is ctrl. Is there a similar abbreviation for CapsLock?
If possible, I would like to use the CapsLock key as a mode key to implement logic like:
if <CapsLock>
map <j>, <Down>
map <k>, <Up>
# ...etc
end
Sorry, that's a mistake on our part listing Capslock on the website. Currently it can only be remapped to Control, Option, or Command via the Keyboard.prefPane under "Modifer Keys.." and there's no way for us right now to detect if it's been pressed.
We'll keep our eyes open for a solution but as of right now it's not going to do what you're wanting. Sorry.
The website has been fixed to avoid any more confusion, as well.
While you can't remap capslock, you can achieve almost the same functionality by adding some basic state to your keymandorc file. I couldn't figure out how to map something to the option key alone, but apart from that, this should do what you are aiming for:
At the top of your keymandorc put:
#caps = false
Then down wherever you define your bindings put something like the following
map "j" do
if #caps then
send("<Down>")
else
send("j")
end
end
map "<Option-v>" do
#caps = !#caps;
alert("Vim Mode: " + #caps.to_s)
end
You could then also bind escape to exit the mode if #caps is true, and so forth.

Identify key uniquely from WM_KEYDOWN message

I tried to use the virtual key code provided by wParam, however that didn't work very well:
multiple keys mapped to the same key code
some keys were not recognized at all
virtual keys seemed to be adapted to the keyboard layout (which i don't want/need)
Then i saw that the lParam will give me a scancode along with an "extended" flag, which seem to produce a different value for every single key on the keyboard when calculated like this:
value = (lParam & 0x01FF0000) >> 16;
Will this value always be identical for the same key on the keyboard, even across various keyboards/systems?
Scancodes can be different for different keyboards. Best to use virtual key codes. From http://msdn.microsoft.com/en-us/library/ms646267(v=vs.85).aspx:
Assigned to each key on a keyboard is a unique value called a scan
code, a device-dependent identifier for the key on the keyboard. A
keyboard generates two scan codes when the user types a key—one when
the user presses the key and another when the user releases the key.
The keyboard device driver interprets a scan code and translates
(maps) it to a virtual-key code, a device-independent value defined by
the system that identifies the purpose of a key.

Resources