Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CapsLock handling #1520

Open
piszoka opened this issue Aug 27, 2017 · 2 comments
Open

CapsLock handling #1520

piszoka opened this issue Aug 27, 2017 · 2 comments

Comments

@piszoka
Copy link

piszoka commented Aug 27, 2017

In the Hungarian layout the "alt + é" and the "capslock / alt + é" is totally different:

  • alt + é ==> …
  • capslock / alt + é ==> ä

See also the attached keymap:
mac-hu-umlaut-a

I would like to bind the "capslock / alt + é" to the "alt + a". To do so, the capslock needs to be activated, the "alt + é" sent and the capslock deactivated again. I tried the following:

hs.hotkey.bind( {'alt'}, 'a', function()

    hs.eventtap.event.newSystemKeyEvent( 'CAPS_LOCK', true):post();
    hs.timer.usleep(1000)
    hs.eventtap.event.newSystemKeyEvent( 'CAPS_LOCK', false):post();      
     
    hs.timer.usleep(1000)

    hs.eventtap.event.newKeyEvent({'alt'}, string.lower('é'), true):post()
    hs.timer.usleep(1000)
    hs.eventtap.event.newKeyEvent({'alt'}, string.lower('é'), false):post()

    hs.timer.usleep(1000)

    hs.eventtap.event.newSystemKeyEvent( 'CAPS_LOCK', true):post();
    hs.timer.usleep(1000)
    hs.eventtap.event.newSystemKeyEvent( 'CAPS_LOCK', false):post();      

end)

But I always get the "…" character, the "alt + é" without the capslock.

Is there a way to:

  • activate and deactivate capslock?
  • to detect capslock current state (activated or deactivated already manually)?
  • to send the 'ä' character as an UTF-8 character or string instead of triggering the keyboard?
@asmagill
Copy link
Member

When the caps lock code was added, I was only able to reliably detect the caps lock through eventtap watchers but not generate it... of course I was focusing on trying to "trigger" the effect of tapping the caps lock, not use it as a key modifier...

Try hs.eventtap.event.newKeyEvent(nil, hs.keycodes.map.capslock, true/false):post() instead of the newSystemKeyEvent lines and let me know if that works any better. (note that the initial nil might need to be {} -- some comments in #1519 that I haven't had a chance to examine yet suggest that there might be a bug in the newKeyEvent code)

@Perlence
Copy link
Contributor

Perlence commented May 9, 2018

@asmagill Unfortunately, sending Caps Lock via hs.eventtap.event.newKeyEvent doesn't work for me. I'd like to map Shift+Escape to Caps Lock but had no luck.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants