{"id":13525583,"url":"https://github.com/SpaceCat-Chan/LoveKeys","last_synced_at":"2025-04-01T05:31:48.516Z","repository":{"id":173735842,"uuid":"256562545","full_name":"SpaceCat-Chan/LoveKeys","owner":"SpaceCat-Chan","description":"a library to track the current state of key presses in Love2D","archived":true,"fork":false,"pushed_at":"2023-11-09T13:27:53.000Z","size":32,"stargazers_count":9,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-11-02T10:32:18.926Z","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/SpaceCat-Chan.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-04-17T17:03:51.000Z","updated_at":"2024-08-12T08:46:33.000Z","dependencies_parsed_at":"2023-11-09T14:43:51.898Z","dependency_job_id":null,"html_url":"https://github.com/SpaceCat-Chan/LoveKeys","commit_stats":null,"previous_names":["spacecat-chan/lovekeys"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SpaceCat-Chan%2FLoveKeys","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SpaceCat-Chan%2FLoveKeys/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SpaceCat-Chan%2FLoveKeys/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SpaceCat-Chan%2FLoveKeys/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/SpaceCat-Chan","download_url":"https://codeload.github.com/SpaceCat-Chan/LoveKeys/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246591314,"owners_count":20801982,"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:20.147Z","updated_at":"2025-04-01T05:31:48.159Z","avatar_url":"https://github.com/SpaceCat-Chan.png","language":"Lua","funding_links":[],"categories":["Input"],"sub_categories":[],"readme":"# LoveKeys\na library to track the current state of key presses in Love2D\n\nthis library has moved away from github and can be found here instead: https://git.ptrc.gay/SpaceCat-Chan/lovekeys\n\n## how to use:\nthere is a simple example in tests/basic\n\nto use the library all that is needed is to require it:\n\n```lua\nLoveKeys = require(\"Path_To_LoveKeys\")\n```\n\nany keys that you expect to use should be registered in love.load\n\n```lua\nfunction love.load()\n\tLoveKeys.RegisterKey(\"up\")\n\tLoveKeys.RegisterKey(\"space\")\n\tLoveKeys.RegisterKey(\"s\")\n\tLoveKeys.RegisterKey(\"Jump\") --you don't need to use actual keys, to see more check out the aliasing section\nend\n```\n\nthen once you have done that, you can get information on the current state of the key in 3 ways:\n\n```lua\nLoveKeys.up.Pressed\n-- or\nLoveKeys[\"space\"].Released\n-- or\nLoveKeys.Get(\"s\").Held\n```\n\nin your love.update you should add LoveKeys.update to the end of it\n\n```lua\nfunction love.update(dt)\n\t--[[\n\t\ta bunch of code\n\t]]\n\n\tLoveKeys.update(dt)\nend\n```\n\nwhen it comes to love.keypressed and love.keyreleased then this is how you should be doing it:\n\n```lua\nfunction love.keypressed(Key)\n\tLoveKeys.keypressed(Key)\nend\n\nfunction love.keyreleased(Key)\n\tLoveKeys.keyreleased(Key)\nend\n```\n\nspecifically you shouldn't have anything else in them, purely because key repeat can't be handled if you do that\n\nif you still want to handle events you can instead define the functions LoveKeys.Event.keypressed and LoveKeys.Event.keyreleased\n\nlike this:\n\n```lua\nfunction LoveKeys.Event.keypressed(KeyName, Key)\n\tprint(KeyName..\" was pressed, it's delay setting is at: \"..Key.Repeat.Delay)\nend\n\nfunction LoveKeys.Event.keyreleased(KeyName, Key)\n\tprint(KeyName..\" was released, it was pressed for \"..Key.PressLength..\" seconds\")\nend\n```\n\n\u0026nbsp;\n\ndefining love.keypressed and love.keyreleased can be annoying so there is a shortcut for that\n\nif the global variable `GLOBAL_SET_LOVE_KEYS` is set to true when LoveKeys is required, it will automatically define both love.keypressed and love.keyreleased to the same as seen above\n\n## about delays and repeats\n\nusing LoveKeys.SetRepeatInfo() it is possible to tell the library how you want a key to repeat\n\n```lua\nLoveKeys.SetRepeatInfo(\"space\", 2, 1)\n```\n\nthe above code will make it so that once the space key has been held for 2 seconds, it will act as if it was pressed again, then again one second later it will do it again and it will keep doing it every second until the space key is released\n\nthe first argument is the delay and the second is the repeat, they can be found in `\u003cKeyInfo\u003e.Repeat.Delay` and `\u003cKeyInfo\u003e.Repeat.Repeat` respectivly\n\nwhen a key is repeating it is possible to tell that it is by checking `\u003cKeyInfo\u003e.Repeating`\n\n\n## Aliasing\n\nAliasing allows you to combine multiple keys into one name  \nit is especially useful if you want your users to be able to change keybinds \n\na basic example of how to create a keybind goes like this: \n\n```lua\nfunction love.load()\n\tLoveKeys.Alias({\"w\", \"up\"}, \"MoveUp\")\nend\n```\n\nwith the above Alias, MoveUp will be pressed if w __or__ up is pressed\n\nboth the first and second argument can be tables or strings interchangably\n\n\u0026nbsp;\n\nthere is an optional third argument which specifies how the keys interact.  \nthe allowed arguments are: `or, and, nor, nand`, the default is `or` \n\n`or` means that if any of the input keys are pressed, the output keys are pressed  \n`and` means that all the input keys must be pressed before the output gets pressed.  \n`nor` and `nand` are inverses of `or` and `and` respectively.\n\nan example can be found in tests/alias/\n\n## Alias namespacing\n\nf you change gamestate and need alot of new keybinds, it can get annoying to have to un-alias and re-alias everything  \nbut with Alias namespacing it is possible to have multiple Alias setups at the same time, with only one of the active at any time\n\nto activate a different namespace from the currently active one you can call `LoveKeys.SetAliasNamespace`\n\nwhen defining Aliases they will by default be set for the currently active namespace, but this can be overridden using the fourth argument\n\n```lua\nfunction love.load()\n\tLoveKeys.SetAliasNamespace(\"The_B_Namespace\")\n\tLoveKeys.Alias(\"a\", \"AAA\", nil, \"The_A_Namespace\")\n\tLoveKeys.Alias(\"b\", \"BBB\",) -- will be defined for currently active namespace, which is: The_B_Namespace\nend\n```\n\nthe default active namespace is `\"default\"`\n\n## Accesing information about keys, advanced mode\n\ni will just dump the format of the table you get from `LoveKeys.Get()` here\n\n```lua\nKeyInfo = {\n\tPressed = true/false,\n\tReleased = true/false,\n\tHeld = true/false,\n\tPressLength = number,\n\tRepeating = true/false,\n\tRepeat = {\n\t\tRepeat = number, --how long between each repeat\n\t\tDelay = number --how long before it starts repeating, once this time is reached another keypress event happens\n\t},\n\tAlias = {\n\t\t[namespace_name1] = {\n\t\t\tTo = Array_Of_Key_Names,\n\t\t\tFrom = Array_Of_Key_Names,\n\t\t\tType = string --valid things are: or, and, nor, nand\n\t\t}\n\t\t[namespace_name2] = ...\n\t\t[...] = ...\n\t}\n}\n```\n\nbeware of accessing information in namespaces, they could be nil\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FSpaceCat-Chan%2FLoveKeys","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FSpaceCat-Chan%2FLoveKeys","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FSpaceCat-Chan%2FLoveKeys/lists"}