Home > Software design >  VkKeyScanExA all TCHAR option list
VkKeyScanExA all TCHAR option list

Time:10-06

I need to make a dll which will simulate a key press. For this I found out you can use an INPUT in combination with SendInput. If you know from the start which key to simulate it is easy because you can look in the list of Virtual-Key Codes and code it from the start with those keys, but I actually need to be able to change them, so I need it to be dynamically selected. In my research I found VkKeyScanExA which is quite nice, because this dll will be used in a native function and from Java I can send a String as the requested key to be pressed, but I ran into a problem, I could not find a complete list of key Strings to give it like i found with Virtual-Key Codes. Can anyone help me with a source that contains a list like the one here Virtual-Key Codes but for VkKeyScanExA? The problem is that if I use "4", it will use the digit 4, but what if the users whats to use num 4?! That is why a complete list would be really helpful.

CodePudding user response:

After a lot of trial and error, and reading the source code from JavaFX, I found a better way to do it. I can simply get the int value of KeyCode from JavaFX and send that in a native function to C and not needing to send a String value I also don't need VkKeyScanExA at all. I'm not used to see an int value in this form 0x03, I though wVk can only get a String or an enum value, but for example 0x03 can be used as an int as well.

Here is a simple example in case someone is having the same use case as me:

a) In java

static native void pressKey(int key);

System.load(System.getProperty("user.dir")   "\\Data\\DLL\\Auto Key Press.dll");
pressKey(KeyCode.HOME.getCode());

b) In C

JNIEXPORT void JNICALL Java_package_Test_pressKey(JNIEnv*, jclass, jint key) {
INPUT ip;
ip.type = INPUT_KEYBOARD;
ip.ki.wVk = (int)key;
ip.ki.wScan = 0;
ip.ki.dwFlags = 0;
ip.ki.time = 0;
ip.ki.dwExtraInfo = 0;
SendInput(1, &ip, sizeof(INPUT));
ip.ki.dwFlags = KEYEVENTF_KEYUP;
SendInput(1, &ip, sizeof(INPUT));
}
  • Related