{"id":13835337,"url":"https://github.com/natural-harmonia-gropius/input-event","last_synced_at":"2025-07-10T07:31:38.278Z","repository":{"id":61151473,"uuid":"548714477","full_name":"natural-harmonia-gropius/input-event","owner":"natural-harmonia-gropius","description":"InputEvent.lua for mpv-player, enhanced input.conf with better, conflict-free, low-latency event mechanism.","archived":false,"fork":false,"pushed_at":"2024-05-12T07:34:23.000Z","size":36,"stargazers_count":38,"open_issues_count":4,"forks_count":3,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-05-19T18:15:54.688Z","etag":null,"topics":["keyevent","mpv","mpv-script"],"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/natural-harmonia-gropius.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,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-10-10T04:16:41.000Z","updated_at":"2024-06-07T04:22:33.531Z","dependencies_parsed_at":"2024-06-07T04:22:32.903Z","dependency_job_id":"b8449aec-66b8-4908-ba25-efbb8f27e800","html_url":"https://github.com/natural-harmonia-gropius/input-event","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"purl":"pkg:github/natural-harmonia-gropius/input-event","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/natural-harmonia-gropius%2Finput-event","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/natural-harmonia-gropius%2Finput-event/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/natural-harmonia-gropius%2Finput-event/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/natural-harmonia-gropius%2Finput-event/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/natural-harmonia-gropius","download_url":"https://codeload.github.com/natural-harmonia-gropius/input-event/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/natural-harmonia-gropius%2Finput-event/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":264545167,"owners_count":23625404,"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":["keyevent","mpv","mpv-script"],"created_at":"2024-08-04T14:00:59.799Z","updated_at":"2025-07-10T07:31:37.511Z","avatar_url":"https://github.com/natural-harmonia-gropius.png","language":"Lua","funding_links":[],"categories":["Input"],"sub_categories":[],"readme":"# InputEvent\n\nThis script enhanced `input.conf` with better, conflict-free, low-latency event mechanism.\n\nIt allows mpv users to bind events by using this syntax in `input.conf`.\n\n```ini\nKEY             command                             #event: event_name\n```\n\nNow the supported events are:  \n`press`, `release`, `repeat`, `click`, `double_click`, `triple_click`, `quatra_click`, `penta_click`\n\nCompound events e.g. `click` will be emitted as soon as possible to get lowest latency.\n\n## How to use?\n\n1. Put [inputevent.lua](https://github.com/natural-harmonia-gropius/input-event/raw/master/inputevent.lua) into `~~/scripts`\n2. Modify your `input.conf`, See [Examples](https://github.com/natural-harmonia-gropius/input-event#Examples) to get common uses\n3. (Recommended) Append `input-doubleclick-time=200` to your `mpv.conf`, if you feel unresponsive due to clicking\n\n## Examples\n\n### Click to pause, Double click to fullscreen\n\n```ini\nMBTN_LEFT       cycle pause                         #event: click\nMBTN_LEFT       cycle fullscreen                    #event: double_click\nMBTN_LEFT_DBL   ignore\n```\n\nLike Youtube, you can click to pause and double click to full screen.  \nBut I'm an mpv user and I wanted to do the same, so I added these into input.conf.\n\n```ini\nMBTN_LEFT       cycle pause\nMBTN_LEFT_DBL   cycle fullscreen\n```\n\nHmm, it does work, but it also pauses when double click, and I don't want that.  \nSo here is the solution.\n\n### Press to speedup, Release to restore\n\n```ini\nSPACE           cycle pause                         #event: click\nSPACE           no-osd set speed 4; set pause no    #event: press\nSPACE           ignore                              #event: release\n```\n\nWhen you press the `SPACE` the playback speed will be 4x faster.  \nWhen you release it, changes will [automatically restore](https://github.com/natural-harmonia-gropius/input-event#how-does-the-auto-restore-on-release-works).\n\nOf course, you can bind it to the right arrow key by simply replacing `SPACE` to `RIGHT`.  \nI just personally prefer the space.\n\n[po5/evafast](https://github.com/po5/evafast) also does this and is more powerful.  \nif you want to use it while having custom keybind, this is an example of integrating it.\n\n```ini\nRIGHT           seek 5                              #event: click\nRIGHT           script-binding evafast/speedup      #event: press\nRIGHT           script-binding evafast/slowdown     #event: release\n```\n\n### Press to maximize/minimize volume\n\n```ini\nUP              add volume  10                      #event: click\nUP              set volume  100                     #event: press\nDOWN            add volume -10                      #event: click\nDOWN            set volume  0                       #event: press\n```\n\nFor the default volume adjustment, repeatedly pressing or holding is annoying, slow and imprecise.  \nNow just one step, press.\n\n### Click to next/prev chapter, Press to next/prev playlist item\n\n```ini\nPGUP            add chapter -1                      #event: click\nPGUP            playlist-prev                       #event: press\nPGDWN           add chapter  1                      #event: click\nPGDWN           playlist-next                       #event: press\n```\n\nIt's convenient for 65-key keyboard users like me.  \n`HOME/END` need be a combination of `fn` + `PGUP/PGDN`, which is not easy to press.\n\n### Press to display stats, Click to toggle\n\n```ini\ni               script-binding stats/display-stats-toggle  #event: click\ni               script-binding stats/display-stats         #event: repeat\ni               script-binding stats/display-stats         #event: press\n```\n\nClick to toggle displaying information and statistics (as default `shift+i`).  \nPress to display information and statistics (as default `i`).  \nThe press line is not required, it just reduces the latency (Very little).\n\n### Press to show uosc UI\n\n```ini\nMBTN_LEFT       script-message-to uosc set-min-visibility 1     #event: press\nMBTN_LEFT       script-message-to uosc set-min-visibility 0     #event: release\n```\n\nRather than click to show, click to hide it is more comfortable to show only when pressed.  \nRequires [tomasklaen/uosc](https://github.com/tomasklaen/uosc).\n\n### Handling repeat, Make it have a different event than click\n\n```ini\n.               frame-step; show-text \"${estimated-frame-number}\"       #event: click\n.               set pause no                                            #event: press\n.               set pause yes; show-text \"${estimated-frame-number}\"    #event: release\n.               show-text \"${estimated-frame-number}\"                   #event: repeat\n```\n\nHere is an example of `frame-step`.  \nThe click here is the same as the default behavior.  \nBut the press of the default is stuttering, now the playback is smooth.\n\n### Handling raw press，Make it have different click, double click events\n\n```ini\nPLAYPAUSE       cycle pause                         #event: click\nPLAYPAUSE       playlist-next                       #event: double_click\n```\n\nSome headphones have a `PLAYPAUSE` button, click to play/pause and double click to play the next, just like some smart headphones.\n\n[Press (the latter if key up/down can't be tracked)](https://mpv.io/manual/master/#lua-scripting-event) will be treated as a click.\n\n## Ideas that are currently impossible\n\n### Press LEFT to rewind\n\nUnfortunately, mpv doesn't support rewind now.\n\n### Press MBTN_RIGHT to start mouse gesture, Release to execute the action\n\nWill not be implemented here, Gesture is a higher level feature.  \nI would prefer this script to be an infrastructure, A better idea is to call other scripts.  \n[omeryagmurlu/mpv-gestures](https://github.com/omeryagmurlu/mpv-gestures)  \n[christoph-heinrich/mpv-touch-gestures](https://github.com/christoph-heinrich/mpv-touch-gestures)\n\n## How does the auto-restore on release works?\n\nWriting the ignore command in the release event will enable automatic restore.  \nWhat if you just need to **ignore** the release? Just don't write the line of release event.\n\n```ini\nKEY             ignore                              #event: release\n```\n\nIn this example [press-to-speedup-release-to-restore](https://github.com/natural-harmonia-gropius/input-event#press-to-speedup-release-to-restore).  \nIf you playing with `speed=0.5; pause=yes`, Press will change them to `speed=4; pause=no`.  \nWhen released, they will restore to `speed=0.5; pause=yes`.\n\nWhen you press, the script will record the current value of properties that will be changed.  \nThen it executes the command in press.  \nWhen you release, it will change the value of these properties to the value of the record.\n\nThe [command-prefixes](https://mpv.io/manual/master/#input-command-prefixes) of press will be retained as is.  \nThe restore for `no-osd set speed 4` will be `no-osd set speed 1`.\n\nOnly `set`, `cycle`, `add`, `multiply` are currently supported for auto-restore.  \nA warning will be given for unsupported commands, `command doesn't support auto restore.`.  \nBut that doesn't mean it doesn't work at all, It will restore the reversible part.\n\n```ini\nSPACE           set speed 4; show-text 1            #event: press\nSPACE           ignore                              #event: release\n```\n\nIn the above example, the speed will be restored, show-text cannot and will not be restored.\n\n## The native press (repeat) doesn't work?\n\nWriting the ignore command in the repeat event will bring back the original behavior of repeat.\n\n```ini\nUP              add volume 1                        #event: click\nUP              ignore                              #event: repeat\n```\n\nIn the above example, if you don't write `UP ignore #event: repeat`, you'll have to press frequently, which is too tiring.\n\n## Extended support for property-expansion\n\n- **Dangerous, use with caution**\n\nThe original property-expansion can only work for strings, but now supports inserting in all positions of the command.\n\nThis is a example of a smoother speedup.\n\n```ini\nSPACE           cycle pause                                                                 #event: click\nSPACE           no-osd set speed 1; set pause no                                            #event: press\nSPACE           ignore                                                                      #event: release\nSPACE           no-osd add speed ${?speed==4.00:0}${!speed==4.00:0.1}; show-text ${speed}   #event: repeat\n```\n\n## Support for multiple configuration files\n\n- For same key, any events in new config will overwrite all events in old config.\n\nYou can spread out the configuration files into multiple ones like this and load them together at runtime.\n\n```ini\nscript-opts-add=inputevent-configs=\"input.conf,~~/test.conf,~~/test.json\"\n```\n\ninput.conf\n\n```ini\nSPACE           cycle pause                         #event: click\nSPACE           set speed  2.0                      #event: press\nSPACE           set speed  1.0                      #event: release\n```\n\ntest.conf\n\n```ini\nSPACE           set speed  0.5                      #event: press\nSPACE           set speed  1.0                      #event: release\n```\n\ntest.json\n\n```json\n[\n  {\n    \"key\": \"SPACE\",\n    \"on\": {\n      \"click\": \"show-text click\",\n      \"double_click\": \"show-text double-click\",\n      \"penta_click\": \"show-text penta-click\",\n      \"press\": \"show-text pressed\",\n      \"quatra_click\": \"show-text quatra-click\",\n      \"release\": \"show-text released\",\n      \"repeat\": \"show-text repeat\",\n      \"triple_click\": \"show-text triple-click\"\n    }\n  }\n]\n```\n\nAlso, it supports hot-reloading.\n\n```ini\n[fullscreen]\nprofile-cond=fullscreen\nprofile-restore=copy-equal\nscript-opts-add=inputevent-configs=\"input.conf,~~/test.json\"\n```\n\n## How to integrate with other scripts?\n\n- For same key, events will be merged with existing events.\n\nHere's an example  \npress `Z` to bind the key, press `C` to test the event execution and press `X` to unbind.\n\nSave it as `test.lua` in your ~~/scripts\n\n```lua\nlocal utils = require(\"mp.utils\")\n\nlocal key = \"c\"\nlocal on = {\n    click = \"show-text click\",\n    double_click = \"show-text double-click\",\n    triple_click = \"show-text triple-click\",\n    quatra_click = \"show-text quatra-click\",\n    penta_click = \"show-text penta-click\",\n    press = \"show-text pressed\",\n    release = \"show-text released\",\n    [\"repeat\"] = \"show-text repeat\",\n}\n\nfunction bind()\n    local json, err = utils.format_json(on)\n    mp.commandv('script-message-to', 'inputevent', 'bind', key, json)\nend\n\nfunction unbind()\n    mp.commandv('script-message-to', 'inputevent', 'unbind', key)\nend\n\nmp.add_forced_key_binding(\"z\", \"test-z\", bind)\nmp.add_forced_key_binding(\"x\", \"test-x\", unbind)\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnatural-harmonia-gropius%2Finput-event","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnatural-harmonia-gropius%2Finput-event","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnatural-harmonia-gropius%2Finput-event/lists"}