My WPF application handles keyboard presses and specifically the # and * character as it is a VoIP phone.
I have a bug though with international keyboards, and in particular the British english keyboard. Normally I listen for the 3 key and if the shift key modifier is down we fire off an event to do stuff. However on the British keyboard this is the ‘£’ character. I found that the UK english keyboard has a dedicated key for ‘#’. Obviously we could just listen for that particular key, but that doesn’t solve the case for US english which is shift-3 and all the countless other keyboards that put it somewhere else.
Long story short, how do I listen for a particular character from a key press, whether it’s a key combo or single key and react to it?
The function below, GetCharFromKey(Key key) will do the trick.
It uses a series of win32 calls to decode the key pressed:
get the virtual key from WPF key
get the scan code from the virtual key
get your unicode character
This old post describes it in a bit more detail.