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

EventTap seems to be sending the event to the wrong window #1334

Open
zen0wu opened this issue Apr 14, 2017 · 5 comments
Open

EventTap seems to be sending the event to the wrong window #1334

zen0wu opened this issue Apr 14, 2017 · 5 comments

Comments

@zen0wu
Copy link

zen0wu commented Apr 14, 2017

It's a bit hard to describe, I'll try my best. Not sure if this is the right place to ask, because I don't know if it's a bug or I'm doing anything wrong with my config. So sorry in advance for spamming.

What I did is, I want CapsLock key to be a hybrid Ctrl/Function key on my new keyboard, for example:

  • caps+B acts like ctrl+B
  • caps+i acts like up arrow
    You get the idea.

My approach is to use an eventTap that's activated when Caps is pressed, and stopped when it's released, the event tap watches keydown event and translate it.

The reason I didn't use modal for it is that,

  • modal is not as responsive
  • modal doesn't work with long press (repeatfn doesn't really work, for some reason that I'm not sure)

The only problem I've found is, Caps-IJKL now are my arrow keys, if I switch a window using Cmd-Tab, then I press Caps-I, it'll actually trigger a up in the previous window. I have to type something real in the new window to make it switch. Not sure if this is a bug, or it's something I'm doing wrong in the config.

Here's my config: https://gist.github.com/shivawu/a28ab3016956db601df0bba37b75546e

@zen0wu
Copy link
Author

zen0wu commented Apr 20, 2017

Anyone available to help?

@cmsj
Copy link
Member

cmsj commented Apr 23, 2017

Rather than modify the event you receive in your eventtap callback, try creating a new hs.eventtap.event event and returning that in the table. I'm guessing here, but it's worth a shot.

@zen0wu
Copy link
Author

zen0wu commented Apr 24, 2017

@cmsj Thanks a lot for the suggestion! Unfortunately it doesn't seem to work

Here's the updated config

local anneEt = hs.eventtap.new({ hs.eventtap.event.types.keyDown }, function(event)
  local kc = event:getKeyCode()
  local mapped = capsMap[inverseKeycodes[kc]]

  if mapped ~= nil then
    key = event:getKeyCode()
    mods = event:getFlags()
    if mapped.key ~= nil then
      key = hs.keycodes.map[mapped.key]
    end
    if mapped.mods ~= nil then
      for _, m in pairs(mapped.mods) do
        mods[m] = true
      end
    end
    return true, {hs.eventtap.event.newKeyEvent(mods, key, true)}
  end

  return false
end)

@cmsj
Copy link
Member

cmsj commented Apr 24, 2017

@shivawu same symptoms as before? :(

@zen0wu
Copy link
Author

zen0wu commented Apr 24, 2017

Yeah... Could you try the same config with "F13" replaced by things like "Caps", should work the same way, right?

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

2 participants