开发者

How to get keyboard keys state on Mac OSX?

开发者 https://www.devze.com 2023-02-28 23:18 出处:网络
Is开发者_如何学C there any way that I can get keyboard keys status (esp. for games) in Mac using only Mono C#?

Is开发者_如何学C there any way that I can get keyboard keys status (esp. for games) in Mac using only Mono C#?

I am looking for purely C# based solution, not any other API. Is there any support like this?


Well, I found myself in the same situation and you either have to use the Control class under System.Windows.Forms, or follow the instructions of this solution and adapt it to the C# world

I was particularly interested in the caps key, so I did:

    [DllImport("/System/Library/Frameworks/ApplicationServices.framework/ApplicationServices")]
    public static extern long CGEventSourceFlagsState(int keyCode);
    bool CapsLock = (CGEventSourceFlagsState(1) & 0x00010000) != 0;

Hope this helps!

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号