bindKey on commands with keyState=both won't trigger on up after restarting the resource
Describe the bug Using bindKey with keyState=both on a command stops triggering on releasing the key after restarting the resource.
To reproduce
local someVariable = false
addCommandHandler("Some Command Handler", function()
someVariable = not someVariable
outputChatBox("State: " .. (someVariable == true and "down" or "up"))
end)
addEventHandler("onClientResourceStart", resourceRoot, function()
bindKey("k", "both", "Some Command Handler")
end)
- Start the resource
- Press 'K' and you will see it working properly
- Restart the resource
- Press 'K' and you will see that it won't trigger when you release the key
Expected behaviour It should also trigger when releasing the key.
Screenshots
Version Server/Client: 1.5.7 Windows 10 Build 18363.778
Additional context
I can reproduce this.
The problem "goes away" if you type unbind k and then restart the resource.
Note that after the resource is stopped, the command binds are still set. I think this is expected behaviour, but I suspect something goes wrong when you try to rebind something that already exists.
stop: Resource stopping
* Current key binds for 'k': *
Command^k down: Some Command Handler
Command^k up: Some Command Handler
Pushing this after 4 years as this has become kinda more relevant due to changes made to the editor resource. There seem to be more issues with the key binds in MTA.
The editor binds it's keys twice, once the down state and once the up state
bindKey ( cc[control.name], "down", control.friendlyName )
bindKey ( cc[control.name], "up", control.friendlyName, "up" )
https://github.com/multitheftauto/mtasa-resources/commit/ced470eb0ead7c48df948a17533fda8cbe656b0d has changed the way objects are being rotated when lctrl is held and the "old behaviour" is moved to rctrl; which makes it quite difficult to use in most cases. If we attempt to undo that change in the users key binding settings (switching mod_rotate: lctrl and mod_rotate_local: rctrl to mod_rotate: rctrl and mod_rotate_local: lctrl) it appears as if only the down command bind is being changed
default:
* Commands bound to "lctrl" (down) *
Rotate Modifier World Space
Clone Drop Modifier
* Commands bound to "lctrl" (up) *
Rotate Modifier World Space
Clone Drop Modifier
changed:
* Commands bound to "lctrl" (down) *
Clone Drop Modifier
Rotate Modifier Local Space
* Commands bound to "lctrl" (up) *
Rotate Modifier World Space
Clone Drop Modifier
This would be fixable if we combine the two bindKey calls into one
bindKey ( cc[control.name], "both", control.friendlyName )
but that brings us back to this issue.