在OS X上独立捕获每个SHIFT键 [英] Trap each SHIFT key independently on OS X

查看:148
本文介绍了在OS X上独立捕获每个SHIFT键的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有有效的代码(此处)为非修饰键按下事件和修饰键更改事件捕获键码.

I have working code (here) that traps keycodes for non-modifier keydown events, and modifier-changed events.

但是,如果您这样做:

LSHIFT down -> RSHIFT down -> RSHIFT up -> LSHIFT up

...内部的2个动作将不会触发这两个钩子,因为修改器的状态没有改变!

... the inner 2 actions will not trigger either of these hooks, because the modifier state is not changing!

(哇!我应该在写之前测试一下,因为实际上每次修改都会产生一个新的修改器.)

我唯一的想法可能是另外观看一个更低的级别(

My only thought is maybe to additionally watch at an even lower level (here) -- but that doesn't look pretty no matter which angle I look at it from.

推荐答案

摘自贾斯汀·布(Justin Boo)的答案

Taken from Justin Boo's answer here

我添加了一些其他修饰符,以防有人偶然发现这一点并想要其他键.

I've added some more modifier just in case someone stumbles upon this and wants other keys as well.

- (void) flagsChanged:(NSEvent*)theEvent{
    if ([theEvent modifier] == 131330){
        //do stuff regarding left shift
    }else if ([theEvent modifier] == 131332){
        //do stuff regarding right shift
    }else if ([theEvent modifier] == 65792){
        //caps lock is on
    }else if ([theEvent modifier] == 8388864){
        //FN key pressed
    }else if ([theEvent modifier] == 262401){
        //control key pressed
    }else if ([theEvent modifier] == 524576){
        //option key pressed
    }else if ([theEvent modifier] == 1048840){
        //command key pressed
    }else if ([theEvent modifier] == 256){
        //there are no modified pressed and caps lock is off
    }
}

我建议在您的类中存储一些BOOL,例如LShiftDownRShiftDown,因为按下修饰符时应调用此方法.您可能还可以在keyDown实现中检测此属性,以检测诸如"a"和"A"之类的差异.

I recommend storing some BOOLs in your class such as LShiftDown and RShiftDown as this method should be called when the modifiers are pressed. You can probably also detect this property in your keyDown implementation to detect differences such as "a" and "A".

这篇关于在OS X上独立捕获每个SHIFT键的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆