diff --git a/button.lua b/button.lua index a1f0589..acdc1df 100644 --- a/button.lua +++ b/button.lua @@ -30,7 +30,7 @@ local mouse = require(BASE .. 'mouse') local keyboard = require(BASE .. 'keyboard') -- the widget --- {text = text, pos = {x, y}, size={w, h}, widgetHit=widgetHit, draw=draw} +-- {text = text, hotkey="key", pos = {x, y}, size={w, h}, widgetHit=widgetHit, draw=draw} return function(w) assert(type(w) == "table" and w.text, "Invalid argument") @@ -72,6 +72,6 @@ return function(w) core.registerDraw(id, w.draw or core.style.Button, w.text, pos[1],pos[2], size[1],size[2]) - return mouse.releasedOn(id) or keyboard.pressedOn(id, 'return') + return mouse.releasedOn(id) or keyboard.pressedOn(id, 'return') or keyboard.pressedHotkey(w.hotkey) end diff --git a/keyboard.lua b/keyboard.lua index 0e52eb3..31b54f8 100644 --- a/keyboard.lua +++ b/keyboard.lua @@ -79,6 +79,10 @@ local function pressedOn(id, k) return (k or 'return') == key and hasFocus(id) and k end +local function pressedHotkey(hotkey) + return hotkey and ( key == hotkey ) +end + local function beginFrame() -- for future use? end @@ -99,6 +103,7 @@ return setmetatable({ hasFocus = hasFocus, makeCyclable = makeCyclable, pressedOn = pressedOn, + pressedHotkey = pressedHotkey, disable = disable, enable = clearFocus,