简体   繁体   中英

How to simulate pressing a custom keyboard key

I have an extended keyboard and I want to simulate the key press of a special key that switches the keyboard mode. For that I think I need to find out key code, but can't figure out how can I get it. It's an extra key on my keyboard, not part of the ConsoleKey enum , and the only functions I've found to catch keys work with this enum .

If the key does something like change the keyboard color, this will depend on whether or not there is software on the computer which can do so as well. If not, this is probably just a local switch to the keyboard and that key isn't on the keymap for the keyboard itself, ether.

If it changes something else, it will depend on if there is driver software for the device or if it uses a default Windows driver.
If it takes installed software, it's probably a custom event (like some joysticks have) and would only be found if you use a reference to a library distributed by the keyboard manufacturer. If it does not, then the switching mode is probably a "remap" mode tied to the keyboard firmware, and just changes which KeyDown event the affected keys send. If this is true, there is no way for Windows to even see what setting the keyboard is on.

I would say the logic for the function key changes is on the keyboard itself. For instance, the Fn key on my laptop does not cast any keyboard events by itself, but when combined with certain other keys, a key code is sent to the OS with a key code that triggers certain functionality.

For instance, in my keyboard Fn + Left lowers the volume, but the virtual key sent to the OS is VK_VOLUME_DOWN (see this for a list of virtual keys.)

Good news is, you can test the keys individually to see which key codes get sent to the OS! To accomplish this, you might want to set up a low-level keyboard hook ) using P/Invokes.

There's a tutorial on CodeProject that may be useful to you.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM