0

I'm developing a program, that does some stuff, while in background, and I need to be able to stop my program or send it some kind of signal as fast as possible.
I could track the mouse position to send the signal by placing mouse to the top left corner of my screen, but if it is a clicker (the program, that controls mouse, changes its position and emulate clicks), it would be barely possible.
Much more rare case is that my program also emulates keyboard, so this input device is free to use, but my task could disallow me to switch currently active application, so I wouldn't be able to use alt+tab to Terminal for ctrl+C.

So I need a way to catch a single key press. For example, it would be fine to stop the program execution by holding Alt.
Would be nice to track the key state via pure Ruby or osascript.
The easily gcc-compilable code would be less nice, but better, than nothing.

Nakilon
  • 34,866
  • 14
  • 107
  • 142
  • C crutch found here: http://stackoverflow.com/questions/4286380/how-to-check-if-option-key-is-pressed-at-startup-of-a-mac-bash-application – Nakilon Feb 02 '14 at 22:13
  • Not sure if this is the easiest way, but I've used the [`rubygame`](https://github.com/rubygame/rubygame/blob/next/lib/rubygame/events/keyboard_events.rb) gem to listen for key presses and joystick events. – AGS Feb 02 '14 at 23:14
  • @AGS, looks like it is `ruby-sdl-ffi` – Nakilon Feb 02 '14 at 23:19

0 Answers0