--- @alias Device "mouse" | "key" | "pad" --- @param device Device --- @param key string local function control(device, key) --- @type {type: Device, key: string} local t = { type = device, key = key } return t end local keymap = { cameraMoveUp = control("key", "w"), cameraMoveLeft = control("key", "a"), cameraMoveRight = control("key", "d"), cameraMoveDown = control("key", "s"), cameraMoveScroll = control("mouse", "3"), select = control("mouse", "1") } function keymap:isDown(key) if not keymap[key] then return false end local type = keymap[key].type local idx = keymap[key].key if type == "key" then return love.keyboard.isDown(idx) end if type == "mouse" then if not tonumber(idx) then return false end return love.mouse.isDown(tonumber(idx) --[[@as number]]) end return false end return keymap