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

Replace timer with eventtap #2

Open
asharpe opened this issue Oct 15, 2016 · 1 comment
Open

Replace timer with eventtap #2

asharpe opened this issue Oct 15, 2016 · 1 comment

Comments

@asharpe
Copy link

asharpe commented Oct 15, 2016

is possible, but the timer option is better because of apps like iTerm that copy directly to the clipboard without the user pressing cmd+c

In any case, here's the code that hooks into cmd+c

local in_copy = false
local copy = hs.eventtap.new({hs.eventtap.event.types.keyDown, hs.eventtap.event.types.keyUp}, function (event)
   if event:getCharacters() == 'c' and event:getFlags().cmd then
      if event:getType() == hs.eventtap.event.types.keyDown then
         in_copy = true
      else
         if in_copy then
            in_copy = false
            just_copied = hs.pasteboard.getContents()
            hs.printf('just copied ' .. just_copied)
         end
      end
   end
end
copy:start()

Thanks for sharing your code, much appreciated :)

@irliao
Copy link

irliao commented Apr 13, 2017

@asharpe your solution worked perfectly, thank you so much!

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