MacOS 日志按键的键码

发布于 2025-01-04 17:56:10 字数 2627 浏览 0 评论 0原文

我需要找出 Mac 的日志按键的按键代码(ctrl、shift 等),或者需要知道如何跟踪此日志按键事件...

基本上我正在将 mac 按键代码转换为等效的 windows 按键代码...如何我可以这样做吗?

+ (unsigned int) winKeyValueForKey:(unsigned int) macKeyValue{
unsigned int mapTable[128];
mapTable[0] = 0;
mapTable[1] = 0;
mapTable[2] = 0;
mapTable[3] = 0;
mapTable[4] = 0;
mapTable[5] = 0;
mapTable[6] = 0;
mapTable[7] = 0;
mapTable[8] = 0;
mapTable[9] = 0;
mapTable[10] = 0;
mapTable[11] = 0;
mapTable[12] = 0;
mapTable[13] = 0;
mapTable[14] = 0;
mapTable[15] = 0;
mapTable[16] = 0;
mapTable[17] = 0;
mapTable[18] = 0;
mapTable[19] = 0;
mapTable[20] = 0;
mapTable[21] = 0;
mapTable[22] = 0;
mapTable[23] = 0;
mapTable[24] = 0;
mapTable[25] = 0;
mapTable[26] = 0;
mapTable[27] = 0;
mapTable[28] = 0;
mapTable[29] = 0;
mapTable[30] = 0;
mapTable[31] = 0;
mapTable[32] = 0;
mapTable[33] = 0;
mapTable[34] = 0;
mapTable[35] = 0;
mapTable[36] = 13; //SHOEB
mapTable[37] = 0;
mapTable[38] = 0;
mapTable[39] = 0;
mapTable[40] = 0;
mapTable[41] = 0;
mapTable[42] = 0;
mapTable[43] = 0;
mapTable[44] = 0;
mapTable[45] = 0;
mapTable[46] = 0;
mapTable[47] = 0;
mapTable[48] = 0;
mapTable[49] = 0;
mapTable[50] = 0;
mapTable[51] = 0;
mapTable[52] = 0;
mapTable[53] = 0;
mapTable[54] = 0;
mapTable[55] = 0;
mapTable[56] = 0;
mapTable[57] = 0;
mapTable[58] = 0;
mapTable[59] = 0;
mapTable[60] = 0;
mapTable[61] = 0;
mapTable[62] = 0;
mapTable[63] = 0;
mapTable[64] = 0;
mapTable[65] = 0;
mapTable[66] = 0;
mapTable[67] = 0;
mapTable[68] = 0;
mapTable[69] = 0;
mapTable[70] = 0;
mapTable[71] = 0;
mapTable[72] = 0;
mapTable[73] = 0;
mapTable[74] = 0;
mapTable[75] = 0;
mapTable[76] = 0;
mapTable[77] = 0;
mapTable[78] = 0;
mapTable[79] = 0;
mapTable[80] = 0;
mapTable[81] = 0;
mapTable[82] = 0;
mapTable[83] = 0;
mapTable[84] = 0;
mapTable[85] = 0;
mapTable[86] = 0;
mapTable[87] = 0;
mapTable[88] = 0;
mapTable[89] = 0;
mapTable[90] = 0;
mapTable[91] = 0;
mapTable[92] = 0;
mapTable[93] = 0;
mapTable[94] = 0;
mapTable[95] = 0;
mapTable[96] = 0;
mapTable[97] = 0;
mapTable[98] = 0;
mapTable[99] = 0;
mapTable[100] = 0;
mapTable[101] = 0;
mapTable[102] = 0;
mapTable[103] = 0;
mapTable[104] = 0;
mapTable[105] = 0;
mapTable[106] = 0;
mapTable[107] = 0;
mapTable[108] = 0;
mapTable[109] = 0;
mapTable[110] = 0;
mapTable[111] = 0;
mapTable[112] = 0;
mapTable[113] = 0;
mapTable[114] = 0;
mapTable[115] = 0;
mapTable[116] = 0;
mapTable[117] = 0;
mapTable[118] = 0;
mapTable[119] = 0;
mapTable[120] = 0;
mapTable[121] = 0;
mapTable[122] = 0;  
mapTable[123] = 37;
mapTable[124] = 39;
mapTable[125] = 40;
mapTable[126] = 38;
mapTable[127] = 0;  
return mapTable[macKeyValue];

}

谢谢

I need to figure out the key code of log keys of Mac(ctrl, shift etc) or need to know how to track this log key press event...

basically I am converting mac key codes to equivalent windows key code...how can I do this?

+ (unsigned int) winKeyValueForKey:(unsigned int) macKeyValue{
unsigned int mapTable[128];
mapTable[0] = 0;
mapTable[1] = 0;
mapTable[2] = 0;
mapTable[3] = 0;
mapTable[4] = 0;
mapTable[5] = 0;
mapTable[6] = 0;
mapTable[7] = 0;
mapTable[8] = 0;
mapTable[9] = 0;
mapTable[10] = 0;
mapTable[11] = 0;
mapTable[12] = 0;
mapTable[13] = 0;
mapTable[14] = 0;
mapTable[15] = 0;
mapTable[16] = 0;
mapTable[17] = 0;
mapTable[18] = 0;
mapTable[19] = 0;
mapTable[20] = 0;
mapTable[21] = 0;
mapTable[22] = 0;
mapTable[23] = 0;
mapTable[24] = 0;
mapTable[25] = 0;
mapTable[26] = 0;
mapTable[27] = 0;
mapTable[28] = 0;
mapTable[29] = 0;
mapTable[30] = 0;
mapTable[31] = 0;
mapTable[32] = 0;
mapTable[33] = 0;
mapTable[34] = 0;
mapTable[35] = 0;
mapTable[36] = 13; //SHOEB
mapTable[37] = 0;
mapTable[38] = 0;
mapTable[39] = 0;
mapTable[40] = 0;
mapTable[41] = 0;
mapTable[42] = 0;
mapTable[43] = 0;
mapTable[44] = 0;
mapTable[45] = 0;
mapTable[46] = 0;
mapTable[47] = 0;
mapTable[48] = 0;
mapTable[49] = 0;
mapTable[50] = 0;
mapTable[51] = 0;
mapTable[52] = 0;
mapTable[53] = 0;
mapTable[54] = 0;
mapTable[55] = 0;
mapTable[56] = 0;
mapTable[57] = 0;
mapTable[58] = 0;
mapTable[59] = 0;
mapTable[60] = 0;
mapTable[61] = 0;
mapTable[62] = 0;
mapTable[63] = 0;
mapTable[64] = 0;
mapTable[65] = 0;
mapTable[66] = 0;
mapTable[67] = 0;
mapTable[68] = 0;
mapTable[69] = 0;
mapTable[70] = 0;
mapTable[71] = 0;
mapTable[72] = 0;
mapTable[73] = 0;
mapTable[74] = 0;
mapTable[75] = 0;
mapTable[76] = 0;
mapTable[77] = 0;
mapTable[78] = 0;
mapTable[79] = 0;
mapTable[80] = 0;
mapTable[81] = 0;
mapTable[82] = 0;
mapTable[83] = 0;
mapTable[84] = 0;
mapTable[85] = 0;
mapTable[86] = 0;
mapTable[87] = 0;
mapTable[88] = 0;
mapTable[89] = 0;
mapTable[90] = 0;
mapTable[91] = 0;
mapTable[92] = 0;
mapTable[93] = 0;
mapTable[94] = 0;
mapTable[95] = 0;
mapTable[96] = 0;
mapTable[97] = 0;
mapTable[98] = 0;
mapTable[99] = 0;
mapTable[100] = 0;
mapTable[101] = 0;
mapTable[102] = 0;
mapTable[103] = 0;
mapTable[104] = 0;
mapTable[105] = 0;
mapTable[106] = 0;
mapTable[107] = 0;
mapTable[108] = 0;
mapTable[109] = 0;
mapTable[110] = 0;
mapTable[111] = 0;
mapTable[112] = 0;
mapTable[113] = 0;
mapTable[114] = 0;
mapTable[115] = 0;
mapTable[116] = 0;
mapTable[117] = 0;
mapTable[118] = 0;
mapTable[119] = 0;
mapTable[120] = 0;
mapTable[121] = 0;
mapTable[122] = 0;  
mapTable[123] = 37;
mapTable[124] = 39;
mapTable[125] = 40;
mapTable[126] = 38;
mapTable[127] = 0;  
return mapTable[macKeyValue];

}

thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

小猫一只 2025-01-11 17:56:10

OS X 上的 Control、Shift、Command 和 Option 键不会生成 NSKeyDown/kCGEventKeyDown 事件。相反,您可以接收 NSFlagsChanged/kCGEventFlagsChanged 事件。

也就是说,“通常”如果用户键入 Option-T 并且您正在扫描 keyDown 事件,您只会看到“T”事件,其中包括以下事实:选项键是“修改”它。

如果您想获取 flagsChanged 事件,您可以通过事件点击或在 NSResponder 某处接收该事件。 flagsChanged 事件告诉您新的修饰符集合(shift/command/etc)。在这种情况下,存储先前修饰符的本地副本会很有帮助,这样您就可以看到哪个特定键按下或按下。

Control, Shift, Command, and Option keys on OS X do not generate NSKeyDown/kCGEventKeyDown events. Instead, you can receive a NSFlagsChanged/kCGEventFlagsChanged event.

That is, "typically" if the user typed Option-T and you are scanning keyDown events, you will only see a "T" event, which includes the fact that the option key is "modifying" it.

If you want to get flagsChanged events, you can receive that with an event tap, or in an NSResponder somewhere. The flagsChanged event tells you the new collection of modifiers (shift/command/etc). In that case, it is helpful to store a local copy of the previous modifiers so you can see which particular key went down or up.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文