The project I am working on needs to record global keystrokes on the keyboard with distinguishing key combinations and which control key (left or right) is held down. It seems the only possible way is to use KeyDown
and KeyUp
events rather than KeyPress
. However, I also need to record which character was typed.
I understand if I use KeyPress
event, I will always get the correct character, but with KeyDown
and KeyUp
events, it will only give the KeyCode which regardless to the key combinations. One of the solutions is to use a Dictionary
to map the Shift keys, but it is not friendly to the international environment as different localised keyboard has different symbols. For example, Shift-2
, gives a @
symbol on US keyboard, but a "
symbol on UK keyboard.
I wonder if there is any way to convert the combination automatically without manually mapping all keyboard layouts?
A slight more complex but off-topic question is, how about if the user use some software key mapping program to give keys different output? e.g., swapping a
and s
key's definition that when typing a
it outputs s
, and vice versa. What will happen for the global hook? I don't have this kind software installed so I can't test it out, anyone has some experience in handling it?