Adobe AIR Keyboard Hook

2019-02-11 03:02发布

I'm trying to add a feature to my AIR app that can listen for (configurable) global keyboard events even when the app is minimized. Ex: CTRL-ALT-SHIFT-F12 to grab a screenshot.

I can't find any way to register a keyboard hook, and listening for keyboard events only captures them when the app has focus. Suggestions?

5条回答
地球回转人心会变
2楼-- · 2019-02-11 03:12

Try hooking onto the stage's KeyboardEvent:

stage.addEventListener(KeyboardEvent.KEY_DOWN,KeyHandler);  

function KeyHandler(e:KeyboardEvent){
    trace ("Key Code: " + e.keyCode);  
    trace ("Control? " + e.ctrlKey);  
    trace ("Shift? " + e.shiftKey);  
    trace ("Alt? " + e.altKey);  
}
查看更多
不美不萌又怎样
3楼-- · 2019-02-11 03:14

I'm testing my Air application in Flash CS5 and I need to disable keyboard shortcuts so I can test my own shortcuts. I can get ctrl-F to work, but ctrl-C will not.

I notice that my keyboard shortcuts WILL work if it's a standard AS3 file that I'm testing.

查看更多
狗以群分
4楼-- · 2019-02-11 03:15

I don't think that Adobe Air programs can process keypress events unless the application is in focus.

http://forums.adobe.com/thread/420446

Even this question regarding a Global handler for keypresses states that the application must be in focus.

查看更多
孤傲高冷的网名
5楼-- · 2019-02-11 03:31

With NativeProcess, you could write an external app pretty easily to listen for global keyboard events and send them back to your AIR app. I might be going down this path now...

查看更多
趁早两清
6楼-- · 2019-02-11 03:32

One method I use is to monitor the clipboard in the AIR app, that only allows you to react based on copied data, but it's at least sort of a way to listen for input when the app does not have focus.

查看更多
登录 后发表回答