How to get keyboard keys state on Mac OSX?
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!
精彩评论