Created
November 10, 2023 13:38
-
-
Save palaniraja/82775eb2bc01eeb9d21bc1e40caf0922 to your computer and use it in GitHub Desktop.
code snippet type simulator (clipboard) for hammerspoon
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
hs.hotkey.bind({"cmd", "shift", "ctrl"}, "v", function() | |
typesim() | |
end) | |
hs.hotkey.bind({"cmd", "shift", "ctrl"}, "s", function() | |
stopType() | |
end) | |
activeTimer = nil | |
txt = nil | |
txtCounter = 0 | |
clipLen = 0 | |
function typesim() | |
print("typesim called") | |
txt = hs.pasteboard.getContents() | |
if (txt ~= nil) then | |
txt = tostring(txt) | |
txtCounter = 0 | |
clipLen = string.len(txt) | |
end | |
activeTimer = hs.timer.new(0.1, function() | |
if (txtCounter < clipLen) then | |
hs.eventtap.keyStrokes(string.sub(txt, txtCounter+1, txtCounter+1)) | |
txtCounter = txtCounter + 1 | |
-- elseif (activeTimer ~= nil) then | |
-- activeTimer:stop() | |
-- print('reached end of clipboard content') | |
else | |
txtCounter = 0 | |
end | |
end) | |
activeTimer:start() | |
end | |
function stopType() | |
print("stopType called") | |
if (activeTimer ~= nil) then | |
activeTimer:stop() | |
txtCounter = 0 | |
print("activeTimer stopped") | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment