pqrs-org / Karabiner-Elements

Karabiner-Elements is a powerful utility for keyboard customization on macOS Sierra (10.12) or later.
https://pqrs.org/osx/karabiner/
The Unlicense
18.57k stars 834 forks source link

access the last key pressed (magic key) #3895

Open TiDemieH opened 1 month ago

TiDemieH commented 1 month ago

I want to implement a key which changes its output based on the last key I pressed (a magic key), for example a key that repeats the last key I pressed. I would like to find which key I pressed last using Karabiner and not a separate keylogger.

Is there a way to use a karabiner keypress-activated shell scripts to either

  1. receive keypresses from karabiner-grabber?
  2. extract logged keypresses from somewhere else like Event-Viewer? (which already has UI logs but I don't know how to interact with that)
  3. detect final output from karabiner's virtual keyboard?

All help is appreciated.

tekezo commented 4 weeks ago

Basically, there's no way to send key inputs outside of karabiner_grabber, and while there are exceptional methods using complex modifications, I wouldn't recommend them. Such approaches could allow other processes to capture keystrokes without permission. I suggest considering whether it's possible to achieve your goal with complex modifications.