键盘代码翻译
Keyboard codes translation
我正在用 C# 创建一些从 Windows 到 Linux 的远程控制工具,我开始工作了。
我面临的唯一问题是将键码从 Windows 翻译成 Linux。是否有任何公式、table 或工具可以进行此转换?
如果有帮助,在 windows 我从 KeyUp/KeyDown 事件中获取关键代码,在 linux 方面我正在使用 uinput 生成事件。
干杯。
好的,我根据 Dietrich Epp 的想法找到了一个优雅的解决方案。这个想法基于使用 USB HID 代码作为中间公共点。
我从 here the linux key mappings to HID and from here 那里得到了 windows 个。
这是最终结果:
public static byte[] linux_hid_keyboard = new byte[]
{
255, 255, 255, 255, 30, 48, 46, 32, 18, 33, 34, 35, 23, 36, 37, 38,
50, 49, 24, 25, 16, 19, 31, 20, 22, 47, 17, 45, 21, 44, 2, 3,
4, 5, 6, 7, 8, 9, 10, 11, 28, 1, 14, 15, 57, 12, 13, 26,
27, 43, 43, 39, 40, 41, 51, 52, 53, 58, 59, 60, 61, 62, 63, 64,
65, 66, 67, 68, 87, 88, 99, 70,119,110,102,104,111,107,109,106,
105,108,103, 69, 98, 55, 74, 78, 96, 79, 80, 81, 75, 76, 77, 71,
72, 73, 82, 83, 86,127,116,117,183,184,185,186,187,188,189,190,
191,192,193,194,134,138,130,132,128,129,131,137,133,135,136,113,
115,114,255,255,255,121,255, 89, 93,124, 92, 94, 95,255,255,255,
122,123, 90, 91, 85,255,255,255,255,255,255,255,111,255,255,255,
255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
255,255,255,255,255,255,179,180,255,255,255,255,255,255,255,255,
255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
255,255,255,255,255,255,255,255,111,255,255,255,255,255,255,255,
29, 42, 56,125, 97, 54,100,126,164,166,165,163,161,115,114,113,
150,158,159,128,136,177,178,176,142,152,173,140,255,255,255,255
};
public static byte[] windows_hid_keyboard = new byte[]
{
255,255,255,255, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76,
77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 49, 50,
51, 52, 53, 54, 55, 56, 57, 48, 13, 27, 8, 9, 32,189,187,219,
221,220,255,186,222,192,188,190,191, 20,112,113,114,115,116,117,
118,119,120,121,122,123, 44,145, 19, 45, 36, 33, 46, 35, 34, 39,
37, 40, 38,144,111,106,109,107,255, 97, 98, 99,100,101,102,103,
104,105, 96,110,255,255,255,255,124,125,126,127,128,129,130,131,
132,133,134,135,255,255,255,255,255,255,255,255,255,255,255,255,
255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
17, 16, 18,255,255,255,255,255,255,255,255,255,255,255,255,255,
255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255
};
public static Dictionary<int, int> GetTranslationWindowsToLinux()
{
Dictionary<int, int> trans = new Dictionary<int, int>();
for (int buc = 0; buc < 256; buc++)
{
int lin = linux_hid_keyboard[buc];
int win = windows_hid_keyboard[buc];
if (lin != 255 && win != 255 && !trans.ContainsKey(win))
trans.Add(win, lin);
}
return trans;
}
public static Dictionary<int, int> GetTranslationLinuxToWindows()
{
Dictionary<int, int> trans = new Dictionary<int, int>();
for (int buc = 0; buc < 256; buc++)
{
int lin = linux_hid_keyboard[buc];
int win = windows_hid_keyboard[buc];
if (lin != 255 && win != 255 && !trans.ContainsKey(lin))
trans.Add(lin, win);
}
return trans;
}
希望对和我情况相同的人有所帮助。
我正在用 C# 创建一些从 Windows 到 Linux 的远程控制工具,我开始工作了。
我面临的唯一问题是将键码从 Windows 翻译成 Linux。是否有任何公式、table 或工具可以进行此转换?
如果有帮助,在 windows 我从 KeyUp/KeyDown 事件中获取关键代码,在 linux 方面我正在使用 uinput 生成事件。
干杯。
好的,我根据 Dietrich Epp 的想法找到了一个优雅的解决方案。这个想法基于使用 USB HID 代码作为中间公共点。
我从 here the linux key mappings to HID and from here 那里得到了 windows 个。
这是最终结果:
public static byte[] linux_hid_keyboard = new byte[]
{
255, 255, 255, 255, 30, 48, 46, 32, 18, 33, 34, 35, 23, 36, 37, 38,
50, 49, 24, 25, 16, 19, 31, 20, 22, 47, 17, 45, 21, 44, 2, 3,
4, 5, 6, 7, 8, 9, 10, 11, 28, 1, 14, 15, 57, 12, 13, 26,
27, 43, 43, 39, 40, 41, 51, 52, 53, 58, 59, 60, 61, 62, 63, 64,
65, 66, 67, 68, 87, 88, 99, 70,119,110,102,104,111,107,109,106,
105,108,103, 69, 98, 55, 74, 78, 96, 79, 80, 81, 75, 76, 77, 71,
72, 73, 82, 83, 86,127,116,117,183,184,185,186,187,188,189,190,
191,192,193,194,134,138,130,132,128,129,131,137,133,135,136,113,
115,114,255,255,255,121,255, 89, 93,124, 92, 94, 95,255,255,255,
122,123, 90, 91, 85,255,255,255,255,255,255,255,111,255,255,255,
255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
255,255,255,255,255,255,179,180,255,255,255,255,255,255,255,255,
255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
255,255,255,255,255,255,255,255,111,255,255,255,255,255,255,255,
29, 42, 56,125, 97, 54,100,126,164,166,165,163,161,115,114,113,
150,158,159,128,136,177,178,176,142,152,173,140,255,255,255,255
};
public static byte[] windows_hid_keyboard = new byte[]
{
255,255,255,255, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76,
77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 49, 50,
51, 52, 53, 54, 55, 56, 57, 48, 13, 27, 8, 9, 32,189,187,219,
221,220,255,186,222,192,188,190,191, 20,112,113,114,115,116,117,
118,119,120,121,122,123, 44,145, 19, 45, 36, 33, 46, 35, 34, 39,
37, 40, 38,144,111,106,109,107,255, 97, 98, 99,100,101,102,103,
104,105, 96,110,255,255,255,255,124,125,126,127,128,129,130,131,
132,133,134,135,255,255,255,255,255,255,255,255,255,255,255,255,
255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
17, 16, 18,255,255,255,255,255,255,255,255,255,255,255,255,255,
255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255
};
public static Dictionary<int, int> GetTranslationWindowsToLinux()
{
Dictionary<int, int> trans = new Dictionary<int, int>();
for (int buc = 0; buc < 256; buc++)
{
int lin = linux_hid_keyboard[buc];
int win = windows_hid_keyboard[buc];
if (lin != 255 && win != 255 && !trans.ContainsKey(win))
trans.Add(win, lin);
}
return trans;
}
public static Dictionary<int, int> GetTranslationLinuxToWindows()
{
Dictionary<int, int> trans = new Dictionary<int, int>();
for (int buc = 0; buc < 256; buc++)
{
int lin = linux_hid_keyboard[buc];
int win = windows_hid_keyboard[buc];
if (lin != 255 && win != 255 && !trans.ContainsKey(lin))
trans.Add(lin, win);
}
return trans;
}
希望对和我情况相同的人有所帮助。