我知道了。经过许多小时的搜索,我设法创建了一种方法,可以将组合转换为当前键盘布局上的组合。它不处理死键(例如重音符号),但是捕获了
[SHIFT+Combinations]我需要捕获的所有内容。
要使用它,请按以下方式调用它:
getCharacter(int vkCode, boolean shiftKeyPressed);
因此,请观看此魔术。如果我想得到
SHIFT+3键盘上的东西(£),请使用:
getCharacter(KeyEvent.VK_3, true);
这是代码:
public static char getCharacter(int vkCode, boolean shiftKeyPressed){ byte[] keyStates = new byte[256]; //Create a keyboard map of 256 keys if (shiftKeyPressed) { keyStates[16]=-127; //Emulate the shift key being held down keyStates[160]=-128; //This needs to be set as well } IntByReference keyblayoutID = User32.INSTANCE.GetKeyboardLayout(0); //Load local keyboard layout int ScanCode = User32.INSTANCE.MapVirtualKeyExW(vkCode, MAPVK_VK_TO_VSC, keyblayoutID); //Get the scanpre char[] buff = new char[1]; int ret = User32.INSTANCE.ToUnipreEx(vkCode, ScanCode, keyStates, buff, 1, 0, _currentInputLocaleIdentifier); switch (ret) { case -1: //Error return (char) -1; case 0: //No Translation return (char) 0; default: //Returning key... return buff[0]; }}以下是声明:
final static int MAPVK_VK_TO_VSC = 0;static IntByReference _currentInputLocaleIdentifier;static interface User32 extends Library { public static User32 INSTANCE = (User32) Native.loadLibrary("User32", User32.class); IntByReference GetKeyboardLayout(int dwLayout); int MapVirtualKeyExW (int uCode, int nMapType, IntByReference dwhkl); boolean GetKeyboardState(byte[] lpKeyState); int ToUnipreEx(int wVirtKey, int wScanCode, byte[] lpKeyState, char[] pwszBuff, int cchBuff, int wFlags, IntByReference dwhkl);}非常感谢BrendanMcK,他帮助我获得了此解决方案。



