05-08-26

Key Press and Scroll Event Logger

This Lua script logs all key presses, releases, and scroll wheel events to the Rebind logs. It's a useful tool for debugging hardware input and understanding how your keys are being used.

rebindlua scriptkey loggerinputhardware inputscriptscroll event

Question

Create a Rebind Lua script that logs key presses and releases to the terminal.

Rebind AI

lua
-- rebind: name=Key Logger

function OnDown(key)
    print("KEY DOWN: " .. key)
    return true
end

function OnUp(key, duration)
    print("KEY UP: " .. key .. " (held " .. duration .. "ms)")
    return true
end

This script logs every key press and release to the Rebind logs tab. The OnDown hook fires when a key is pressed and shows the key name. The OnUp hook fires when it's released and shows how long it was held in milliseconds.

All output appears in the Rebind UI Logs tab. print() is an alias for Log.Info() — both work the same way.

If you want to see mouse buttons and scroll events too, you can add:

lua
function OnScroll(delta)
    print("SCROLL: " .. delta)
    return true
end

Question

Provide the complete script in a single copy-and-paste block.

Rebind AI

lua
-- rebind: name=Key Logger

function OnDown(key)
    print("KEY DOWN: " .. key)
    return true
end

function OnUp(key, duration)
    print("KEY UP: " .. key .. " (held " .. duration .. "ms)")
    return true
end

function OnScroll(delta)
    print("SCROLL: " .. delta)
    return true
end

Copy this entire script into a new module in the Rebind UI. It logs all key presses, releases (with hold duration), and scroll events to the Logs tab.