VkKeyScanExA 所有 TCHAR 选项列表

VkKeyScanExA all TCHAR option list

我需要制作一个模拟按键的 dll。为此,我发现你可以使用一个 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,这非常好,因为这个 dll 将在本机函数中使用,并且从 Java 我可以发送一个字符串作为要按下的请求键,但是我 运行 遇到了一个问题,我找不到一个完整的关键字符串列表来提供它,就像我发现的那样 Virtual-Key Codes. Can anyone help me with a source that contains a list like the one here Virtual-Key Codes but for VkKeyScanExA?问题是,如果我使用“4”,它将使用数字 4,但是如果用户使用数字 4 怎么办?!这就是为什么完整列表会非常有用的原因。

经过多次试验和错误,并阅读了 JavaFX 的源代码,我找到了更好的方法。我可以简单地从 JavaFX 获取 KeyCode 的 int 值,然后将其以本机函数的形式发送到 C++,而无需发送 String 值,我也根本不需要 VkKeyScanExA。我不习惯看到这种形式的 int 值 0x03,我虽然 wVk 只能得到一个 String 或一个枚举值,但是例如 0x03 可以用作 int还有。

这是一个简单的例子,以防有人和我有相同的用例:

a) 在 java

static native void pressKey(int key);

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

b) 在 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));
}