05-03-26
Input Choreography Lua Script
Create and playback custom input sequences with this Lua script for hardware input. Record, edit, and replay keyboard and mouse actions with adjustable speed using the Rebind platform.
Question
Can you provide a script for input choreography with demo playback?
Rebind AI
Here's a script for input choreography with demo playback:
-- rebind: min_sdk=0.1.0
-- rebind: name=Input Choreography
-- rebind: description=Playback scripted input sequences with timing control
local cfg = UI.Schema({
speed = UI.Slider(100, { min = 25, max = 400, suffix = "%", label = "Playback Speed" }),
play = UI.Keybind("F9", { label = "Play Sequence" }),
stop = UI.Keybind("F10", { label = "Stop" }),
record = UI.Keybind("F11", { label = "Record Sequence" }),
sequence_name = UI.Text("demo", { label = "Sequence Name", maxLength = 30 }),
})
local isRecording = false
local playbackHandle = nil
local recordedSequence = nil
-- Example choreography sequences (can be extended with more demos)
local sequences = {
["typing_demo"] = {
{ action = "type", text = "Hello from Rebind!", charDelay = 50, delay = 100 },
{ action = "press", code = "Enter", holdMs = 50, delay = 200 },
},
["mouse_pattern"] = {
{ x = 10, y = 0, delay = 20 },
{ x = 10, y = 10, delay = 20 },
{ x = 0, y = 10, delay = 20 },
{ x = -10, y = 10, delay = 20 },
{ x = -10, y = 0, delay = 20 },
{ x = -10, y = -10, delay = 20 },
{ x = 0, y = -10, delay = 20 },
{ x = 10, y = -10, delay = 20 },
},
["keyboard_combo"] = {
{ action = "press", code = "LCtrl+A", holdMs = 50, delay = 100 },
{ action = "press", code = "LCtrl+C", holdMs = 50, delay = 100 },
{ action = "press", code = "End", holdMs = 30, delay = 100 },
{ action = "press", code = "Enter", holdMs = 50, delay = 200 },
{ action = "press", code = "LCtrl+V", holdMs = 50, delay = 0 },
},
["clicking_sequence"] = {
{ action = "press", code = "Mouse1", holdMs = 50, delay = 200 },
{ action = "sleep", delay = 300 },
{ action = "press", code = "Mouse1", holdMs = 50, delay = 200 },
{ action = "sleep", delay = 300 },
{ action = "press", code = "Mouse1", holdMs = 50, delay = 0 },
},
}
function OnStart()
File.MkDir("choreography")
Log.Info("Input Choreography ready. Available sequences: " .. table.concat({ "typing_demo", "mouse_pattern", "keyboard_combo", "clicking_sequence" }, ", "))
end
-- Play a named sequence or recorded data
local function playSequence(seq, speedFactor)
if not seq or #seq == 0 then
UI.Notify("Empty sequence", "warning")
return nil
end
local scaled = Math.TimeComp(seq, 1000 / speedFactor)
return Macro.Play(scaled, speedFactor, "replace")
end
-- Record input to a macro
Bind(cfg.record, function()
if isRecording then
recordedSequence = Macro.Finish()
if recordedSequence and #recordedSequence > 0 then
local filename = "choreography/" .. cfg.sequence_name .. ".json"
File.WriteJSON(filename, recordedSequence)
UI.Notify("Recorded: " .. cfg.sequence_name, "success")
Log.Info("Saved to " .. filename)
recordedSequence = nil
else
UI.Notify("Recording empty", "warning")
end
isRecording = false
Audio.Beep()
else
Macro.Record({ precision = "high" })
UI.Notify("Recording...", "info")
Audio.Beep()
isRecording = true
end
return false
end)
-- Play sequence by name or load from file
Bind(cfg.play, Async(function()
if isRecording then
UI.Notify("Stop recording first", "warning")
return false
end
local name = cfg.sequence_name
local seq = sequences[name]
-- Try to load from file if not in built-ins
if not seq and File.Exists("choreography/" .. name .. ".json") then
seq = File.ReadJSON("choreography/" .. name .. ".json")
end
if not seq then
UI.Notify("Sequence not found: " .. name, "error")
return false
end
local speedFactor = cfg.speed / 100
playbackHandle = playSequence(seq, speedFactor)
if playbackHandle then
UI.Notify("Playing: " .. name, "info")
playbackHandle:Wait()
UI.Notify("Finished: " .. name, "success")
end
return false
end))
-- Stop playback
Bind(cfg.stop, function()
if isRecording then
Macro.Finish()
isRecording = false
UI.Notify("Recording stopped", "info")
end
if playbackHandle and playbackHandle:IsPlaying() then
playbackHandle:Stop()
playbackHandle = nil
UI.Notify("Playback stopped", "info")
end
return false
end)
function OnStop()
if isRecording then
Macro.Finish()
isRecording = false
end
if playbackHandle then
playbackHandle:Stop()
playbackHandle = nil
end
end
function OnBlur()
if isRecording then
Macro.Finish()
isRecording = false
end
if playbackHandle then
playbackHandle:Stop()
playbackHandle = nil
end
endThis script provides a complete input choreography system with three modes:
-
Playback Built-in Sequences – Four example choreographies demonstrate different input types:
typing_demo: Types text with character delaysmouse_pattern: Draws an octagon with mouse movementskeyboard_combo: Performs select/copy/paste operationsclicking_sequence: Multi-click pattern with delays
-
Record Custom Sequences – Press the Record key (F11 default) to start recording. All keyboard, mouse, and scroll input is captured. Press again to stop and save as a JSON file in the
choreography/folder. -
Speed Control – Slider adjusts playback speed from 25% to 400% without changing sequence structure.
Key features:
- Named sequences stored in JSON for easy sharing/editing
- Macro transforms (TimeComp) normalize timing based on speed factor
- Recording saves with automatic filenames
- Plays recorded sequences alongside built-ins
- Progress callbacks with notifications
- Clean shutdown (cancels active playback on blur/exit)
UI Controls:
- Play Sequence (F9) – Plays the named sequence at configured speed
- Stop (F10) – Stops current playback or recording
- Record Sequence (F11) – Toggle recording on/off
- Speed – Scales all playback timing
- Sequence Name – Which sequence to play or save as
Usage:
- Pick a name in the text field, press F11 to record input
- Perform your choreography (typing, clicking, moving mouse)
- Press F11 again to save
- Change the name field and press F9 to replay any recorded sequence
- Adjust speed slider to slow down or accelerate playback
Learn more: