Skip to content

Instantly share code, notes, and snippets.

@palaniraja
Created November 10, 2023 13:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save palaniraja/82775eb2bc01eeb9d21bc1e40caf0922 to your computer and use it in GitHub Desktop.
Save palaniraja/82775eb2bc01eeb9d21bc1e40caf0922 to your computer and use it in GitHub Desktop.
code snippet type simulator (clipboard) for hammerspoon
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