Skip to main content

Keyboard Hook API Reference

This documentation covers the keyboard hook API available in Aurora, which allows modules to register and handle keyboard events outside of WoW's default input system.

Key Code Enumeration

Aurora provides a comprehensive enumeration of virtual key codes through the Aurora.HotkeyEnum table, which maps keyboard keys to their corresponding virtual key codes.

-- Example key codes
Aurora.HotkeyEnum.A -- Virtual key code for 'A'
Aurora.HotkeyEnum.SHIFT -- Virtual key code for left Shift
Aurora.HotkeyEnum.SPACE -- Virtual key code for Space

Key Binding System

The Aurora.KeyBindingSystem provides methods for registering and handling keyboard shortcuts.

Registering Key Bindings

-- Register a key binding using WoW-style hotkey string
Aurora.KeyBindingSystem:RegisterWoWHotkey("SHIFT-A", function(isPressed)
if isPressed then
-- Handle key press
print("Shift+A pressed")
end
end)

-- Register using raw key codes
local keyCodes = {Aurora.HotkeyEnum.CONTROL, Aurora.HotkeyEnum.C}
Aurora.KeyBindingSystem:RegisterKeyBinding(keyCodes, function(isPressed)
if isPressed then
-- Handle Ctrl+C
print("Control+C pressed")
end
end)

-- Register using a hotkey string
Aurora.KeyBindingSystem:RegisterHotkeyString("ALT-F4", function(isPressed)
if isPressed then
-- Handle Alt+F4
print("Alt+F4 pressed")
end
end)

Unregistering Key Bindings

-- Unregister a WoW-style hotkey
Aurora.KeyBindingSystem:UnregisterHotkeyString("SHIFT-A")

-- Unregister using key codes
local keyCodes = {Aurora.HotkeyEnum.CONTROL, Aurora.HotkeyEnum.C}
Aurora.KeyBindingSystem:UnregisterKeyBinding(keyCodes)

-- Clear all key bindings
Aurora.KeyBindingSystem:ClearKeyBindings()

Working with Hotkey Strings

Aurora provides utilities for parsing and creating hotkey strings:

-- Parse a hotkey string into components
local hotkeyComponents = Aurora.HotkeyEnum:ParseHotkeyString("CTRL-SHIFT-A")
-- Result: { modifiers = {"CTRL", "SHIFT"}, key = "A" }

-- Create a hotkey string from components
local hotkeyString = Aurora.HotkeyEnum:CreateHotkeyString({"SHIFT", "ALT"}, "B")
-- Result: "SHIFT-ALT-B"

-- Convert between WoW key names and virtual key codes
local keyCode = Aurora.HotkeyEnum:FromWoWKey("A") -- Get key code for 'A'
local keyName = Aurora.HotkeyEnum:ToWoWKey(0x00) -- Get name for key code (returns "A")

-- Convert a hotkey string to virtual key codes
local keyCodes = Aurora.HotkeyEnum:HotkeyStringToKeyCodes("SHIFT-A")

-- Convert virtual key codes to a hotkey string
local hotkeyString = Aurora.HotkeyEnum:KeyCodesToHotkeyString({0x38, 0x00}) -- "SHIFT-A"

Short Example

-- Read the hotkey binding from config
local binding = Aurora.Config:Read("my_ability_hotkey")

-- Register the binding with the KeyBindingSystem
if binding and binding ~= "" then
Aurora.KeyBindingSystem:RegisterWoWHotkey(binding, function(isPressed)
if isPressed then
print("My ability activated!")
end
end)
end