Is it possible to install a keyboard listener without having a window?


I’d really want to create a library that detect keypresses, so I am interested to know if that is possible, without having a window in foreground. I’m thinking about a pure AsOC solution, as it is so easy to distribute. :slight_smile:

I’m thinking about creating a delegate, and set that up as firstResponder, As I initialize the handler that will also check for the return value from the keypress.

Is it impossible without a window, or is there anything else that renders it impossible to do?

I don’t think you can make a first responder outside a window of some sort. I don’t see any ASObjC solution. You can build a window easily enough on the fly, though.


I figured out the obvious solution:

An AsOC library is a bundle, so I could just as easily stuff something into the resources folder, a much better idea than trying to fake NSWindow/NSView anyway. (I don’t think I can make an invisible window get input.)

I saw that the Application object could only trap some keystrokes, and the rest goes to the window.


I’ll try to make a 100% translucent borderless window the key window, with a size 100x100 in the centre of the screen. :slight_smile:
Don’t hold your breath.


I have a lot of saving to do, as the frameworks can’t be found again. But then, I look forward to try the code below. :slight_smile:

framework "AppKit"

on modiflags()
	return current application's NSEvent's modifierFlags()
end modiflags

FYI, if you go to and, in the box at top-right, click where it says “Click here to download some sample scripts”, there’s a good example of a modifier keys script, including a version with terminology defined.

Thanks Shane.

I wasn’t very clear about the kind of keypress I was after for starters, sorry about that.

The solution here seems a bit easier than installing callbacks into IOKit. :slight_smile:

Thanks for the link Shane, that was a truly great and instructive collection of AsObjC scripts.

It is important to read the small print! :slight_smile: