{"id":13525544,"url":"https://github.com/xiejiangzhi/input","last_synced_at":"2025-04-01T05:31:46.782Z","repository":{"id":147735262,"uuid":"325220498","full_name":"xiejiangzhi/input","owner":"xiejiangzhi","description":"Input for Love2D","archived":false,"fork":false,"pushed_at":"2021-01-04T05:58:56.000Z","size":37,"stargazers_count":4,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"main","last_synced_at":"2024-08-02T06:17:41.143Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Lua","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/xiejiangzhi.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2020-12-29T07:43:17.000Z","updated_at":"2024-07-24T22:29:50.000Z","dependencies_parsed_at":"2023-05-27T08:34:57.651Z","dependency_job_id":null,"html_url":"https://github.com/xiejiangzhi/input","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xiejiangzhi%2Finput","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xiejiangzhi%2Finput/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xiejiangzhi%2Finput/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xiejiangzhi%2Finput/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/xiejiangzhi","download_url":"https://codeload.github.com/xiejiangzhi/input/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":222703633,"owners_count":17025835,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-01T06:01:19.815Z","updated_at":"2024-11-02T10:30:34.062Z","avatar_url":"https://github.com/xiejiangzhi.png","language":"Lua","funding_links":[],"categories":["Input"],"sub_categories":[],"readme":"Input\n===========\n\nSimple and powerful input handler for LOVE2D.\n\n## Features\n\n* Support keyboard, mouse, joystick\n* Check key is down with delay and interval. And can get duration time.\n* Check pressed or released on current frame.\n* Check multiple keys down with delay and interval.\n* Check sequence keys down with interval limit.\n* Get pressed keys.\n* Get history of pressed keys.\n\n## Example\n\n```lua\nlocal Input = require 'input'\n\nfunction love.load()\n  Input.bind_callbacks()\nend\n\nfunction love.update(dt)\n  local delay, interval = 0.5, 1\n  local is_down, _, duration = Input.down('a', delay, interval)\n  local is_down, val, duration = Input.down('leftx')\n  local is_pressed, data, released_duration = Input.pressed('a')\n  local is_released, data, pressed_duration = Input.released('leftx')\n  local is_down = Input.multidown({ 'a', 'b' }, delay, interval)\n  local min_interval, max_interval = 0, 0.3\n  local is_down, data_of_last_key = Input.sequence({ 'a', 'b' }, min_interval, max_interval)\n\n  local keys = iNput.get_down_keys()\n  local keys_info = Input.get_history(2)\nend\n```\nBetter example please see [here](https://github.com/xiejiangzhi/input/blob/main/main.lua)\n\n## API\n\n### Bind callbacks\n\nCall it to setup input callbacks.\n\n`Input.bind_callbacks()`\n\n\n### Check key is down\n\n`is_down, data, duration = Input.down(key, delay, interval)`\n\n`delay` and `interval` unit seconds\n\n`data` is the axis value for axis key. nil for normal key\n`duration` is the duration time in second.\n\n```lua\n-- for normal key\nlocal is_down, data, duration = Input.down('1')\nif is_down then assert(data == nil) end\n\n-- for mouse\nlocal is_down, pos, duration = Input.down('mouse1')\nif is_down then print(pos.x, pos.y) end\n\n-- for gamepad axis\nlocal is_down, axis_val, duration = Input.down('leftx')\nif is_down then assert(type(data) == 'number') end\n\n-- for wheel\nlocal is_down, wheel_val, duration = Input.down('wheelx')\nif is_down then assert(type(wheel_val) == 'number') end\n```\n\n\n### Check multiple keys is down\n\n`is_down, data_of_last_key, duration = Input.multidown(keys, delay, interval)`\n\n`delay` and `interval` unit seconds\n\n```\nlocal is_down, mouse_pos, duration = Input.multidown({ 'fdown', 'mouse1' }, 1, 1)\n```\n\n\n### Check a key is pressed on the current frame\n\n`is_pressed, data, released_time = Input.pressed(key)`\n\n`data` is the axis value for axis key. nil for normal key\n`released_time` will be nil for first call\n\n\n### Check a key is released on the current frame\n\n`is_released, data, released_time = Input.released(key)`\n\n`data` is the axis value for axis key. nil for normal key\n`released_time` will be nil for first call\n\n\n### Check keys is down in sequence\n\n`is_pressed, data_of_last_key = Input.sequence(keys, min_interval, max_interval)`\n\n\n```lua\n  -- any interval\n  Input.sequence({ 'a', 'b', 'c' })\n\n  -- The interval between two presses must be less than 0.3s and greater than 0.1s\n  Input.sequence({ 'a', 'b', 'c' }, 0.1, 0.3)\n```\n\n\nNOTE: Following keys is invalid for sequence, but you can change the set by `Input.sequence_except_keys`\n\n```lua\n-- Default value\nInput.sequence_except_keys = {\n  mousemove = true,\n  wheelx = true, wheely = true,\n  leftx = true, lefty = true,\n  rightx = true, righty = true\n}\n\n-- Except sequence keys 'a', 's' 'd' and 'w'\nfor i, k in ipairs({ 'a', 's', 'd', 'w' }) do\n  Input.sequence_except_keys[k] = true\nend\n```\n\n### Get a relative to time of the last action(pressed or released)\n\n`seconds = Input.duration(key, strict)`\n\n`strict`: Whether to calculate the exact time. Default value is false, duration relative to last frame.\n\nReturn nil if the key has never been down\n\n\n### Get the history of pressed keys. Max history items is 10.\n\n`items = Input.get_history(n)`\n\n`items`: Sort by pressing time from nearest to far.\n`item.key`:\n`item.interval`: relative to the time of previous key was pressed\n\n\n### Get all down keys\n\n`keys = Input.get_down_keys`\n\n\n### Get key data\n\n\n`data = Input.get_data(key)`\n\n\n### Manually input event\n\nCall following callbacks, the arguments is the same as Love2D's callbacks\n\n```lua\nlocal Callbacks = {\n  'keypressed', 'keyreleased',\n  'mousepressed', 'mousereleased', 'mousemoved', 'wheelmoved',\n  'gamepadpressed', 'gamepadreleased', 'gamepadaxis'\n}\n```\n\nExample\n\n```\nInput.keypressed('a')\nInput.keyreleased('a')\n```\n\n\n## Axis threshold\n\nRelease axis key if axis value \u003c threshold, but still can get the current axis value by `Input.get_data`\n\n```\nInput.axis_threshold = {\n  leftx = 0.1, lefty = 0.1,\n  rightx = 0.1, righty = 0.1,\n  l2 = 0.1, r2 = 0.1,\n}\n```\n\n## Multiple gamepad\n\nSet `Input.multiple_gamepad = true`, then all gamepad keys will has a suffix `{key}:{index}`\n\nThe first trigger gamepad will get index 1, others will be automatically incremented\n\n```\nInput.multiple_gamepad = true\nInput.down('fdown:1') -- first gamepad\nInput.down('fdown:2') -- seconds gamepad\n```\n**NOTE**: Now, multiple gamepad keys will push to one list, so `Input.sequence` cannot use specified gamepad index. Maybe it will be fixed later\n\n## Keys\n\n**keyborad** [Key Constant](https://love2d.org/wiki/KeyConstant)\n\n**Mouse**\n```\nlocal MouseKeysMapping = {\n  move = 'mousemove',\n  wheelx = 'wheelx', wheely = 'wheely',\n  [1] = 'mouse1', [2] = 'mouse2', [3] = 'mouse3',\n  [4] = 'mouse4', [5] = 'mouse5', [6] = 'mouse6',\n}\nlocal WheelKeysMapping = {\n  x = 'wheelx', y = 'wheely'\n}\n```\n\n**Gamepad**\n\n```\nlocal GamepadKeysMapping = {\n  a = 'fdown', y = 'fup', x = 'fleft', b = 'fright',\n  back = 'back', guide = 'guide', start = 'start',\n  leftstick = 'leftstick', rightstick = 'rightstick',\n  leftshoulder = 'l1', rightshoulder = 'r1',\n  dpup = 'dpup', dpdown = 'dpdown', dpleft = 'dpleft', dpright = 'dpright',\n\n  -- axis\n  leftx = 'leftx', lefty = 'lefty',\n  rightx = 'rightx', righty = 'righty',\n  triggerleft = 'l2', triggerright = 'r2'\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fxiejiangzhi%2Finput","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fxiejiangzhi%2Finput","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fxiejiangzhi%2Finput/lists"}