-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinit.lua
More file actions
81 lines (64 loc) · 2.09 KB
/
init.lua
File metadata and controls
81 lines (64 loc) · 2.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
local steps = {
"Make the text bigger and orange",
"Make the background much brighter",
"Hide search input behind a search icon toggle",
"Apply my suggestions"
}
local i = 1
local speed = 0.1
-- Path to keyboard typing sound (place keyboard-click.wav in ~/.hammerspoon/)
local keySoundPath = hs.configdir .. "/keyboard-click-2.wav"
-- helper to type text at fixed speed
local function typeOut(text, delay)
local len = #text
local pos = 1
local t = hs.timer.doEvery(delay, function()
if pos <= len then
hs.eventtap.keyStrokes(text:sub(pos, pos))
pos = pos + 1
else
t:stop()
end
end)
end
local function typeOutNatural(text)
local pos = 1
local function typeNext()
if pos <= #text then
local ch = text:sub(pos, pos)
-- Play the typing sound (create new instance each time for proper playback)
-- local keySound = hs.sound.getByFile(keySoundPath)
-- if keySound then
-- -- Vary volume between 0.7 and 1.0 for variety
-- -- local volume = 0.5 + math.random() * 0.5
-- -- keySound:volume(volume)
-- keySound:play()
-- end
if ch == "\n" then
-- Send a Return key instead of trying to "type" the newline
hs.eventtap.keyStroke({}, "return")
else
hs.eventtap.keyStrokes(ch)
end
pos = pos + 1
local jitter = speed * 0.25 + math.random() * speed * 0.75 -- adds variation
hs.timer.doAfter(jitter, typeNext)
end
end
typeNext()
end
hs.hotkey.bind({"shift", "cmd"}, "P", function()
if hs.eventtap.isSecureInputEnabled() then
hs.alert.show("Secure Input is ON; can't type here.")
return
end
if steps[i] then
-- typeOut(steps[i], speed) -- 0.05s between chars (20 cps)
typeOutNatural(steps[i])
-- hs.alert.show(("Step %d/%d"):format(i, steps), 0.6)
if i < #steps then i = i + 1 end
end
end)
hs.hotkey.bind({"shift", "alt"}, "P", function()
i = 1
end)