开发者

How to determine a PHYSICAL key?

I want to hook the keyboard and make some actions (in vb.net) when a specific physical key is pressed.

I开发者_StackOverflow have found online several excellent keyboard hook dlls, but there is a problem: the hook dlls find the keycode of the pressed keys, not what physical key is pressed.

So, for example, in a USA keyboard if I press the key on the left of the Right-Shif key I see the e.keycode: 191 (OemQuestion), in a italian keyboard I see the e.keycode 189 (OemMinus).

This means that if I put in My.Settings the code "189", an italian user can see that has to press the key I want, an USA user see another key to press to have the same action because on it keyboard the OemMinus key is not on the left of the Right-Shift key.

Now the question is: how to determine univocally the keyboard keys? What do I have to put in My.Settings that determinate a specific physical key, the same for all the keyboard languages?


I don't think that you should implement it with so-called "physical" keys. Basically you would have to know mapping from keycode to "physical" key of every keyboard layout that exists, including customized keyboard layouts (that are unknown to you).

Therefore I recommend that you do like everyone else; use keycode (eg. symbol on keyboard) and not key placement on keyboard (what you call "physical key").


I imagine that you would need to physically hook into the keyboard's key switches to do this. As I recall, the keyboard only sends key codes, which may or may not have any resemblence whatsoever to the physical position of the key switch on the circuit board. See for example this post from The Old New Thing.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜