Mudlet icon indicating copy to clipboard operation
Mudlet copied to clipboard

Add: getKeyCode function to return key code and any modifiers of a key-binding

Open SlySven opened this issue 2 months ago • 3 comments

Brief overview of PR changes/additions

Adds getKeyCode(keyBindingName/ID) and returns two integer values, the key "code" and the "modifiers" if any for the specified keybinding.

This, used in conjuction with findItems("", "keybinding", false) to get the ID numbers of all extant key-binding will allow a script/package/end- user to determine whether a particular key has already had a binding assigned to it to avoid unwanted multiples bindings to the same key or key and modifier.

Motivation for adding to Mudlet

A discussion initiated at 2025/10/22 06:52 UTC in Mudlet's Discord #mudlet-development channel by the new user @zygmud.

can I ask a small question here?

I would like to check if a hotkey exists, without knowing its ID or name. Just check if a keybind exists on a given key, like mudlet.key.F12, for example, is this possible?

I'm writing a script for others to import, and I don't want to overwrite existing settings

Other info (issues closed, discussion etc)

The numbers returned are the same as defined in the mudlet.key and mudlet.keymodifier tables as listed in the .\src\mudlet-lua\lua\KeyCodes.lua file in the source code.

SlySven avatar Oct 24 '25 13:10 SlySven

Test builds: Windows (x86_64): https://make.mudlet.org/snapshots/cd8888/Mudlet-4.19.1-testing-pr8435-67642e0b-windows-64.zip Linux (x86_64): https://make.mudlet.org/snapshots/394f6d/Mudlet-4.19.1-testing-pr8435-67642e0b-linux-x64.AppImage.tar MacOS (x86_64): https://make.mudlet.org/snapshots/eeb924/Mudlet-4.19.1-testing-pr8435-67642e0b-x86_64.dmg MacOS (Arm64): https://make.mudlet.org/snapshots/a973d1/Mudlet-4.19.1-testing-pr8435-67642e0b-arm64.dmg

SlySven avatar Oct 24 '25 18:10 SlySven

Nice nice. I added some improvements on top of this, see https://github.com/SlySven/Mudlet/pull/93

vadi2 avatar Oct 26 '25 08:10 vadi2

:pen: Guess I need to write some documentation for this now...!

SlySven avatar Oct 26 '25 11:10 SlySven