Page 1 of 1

[0.13.x +] Mod API: Add KeyUp Event

Posted: Wed Jul 06, 2016 7:42 pm
by Bizz Keryear
Run into the problem that I needed to figure out when a key is held down.
was about to propose something about implementing about implementing .KeyDown and retriggering every tick and such ...

Anyway (TL;DR):
... Then I realized a key is held down when it isn't up.
  • What I suggest now is an on_KeyUp event for the Mod API, which is triggered when a key is released. I am pretty sure that is a thing that is already ready made somewhere ready to picked up.

    Code: Select all

    script.on_event(defines.events.on_keyup([key name here]), [function name here])
    This will trigger as soon as they key is released

    Example:
    A code that looks like this (assuming that my_key is set in data.lua)

    Code: Select all

    function on_press(event)
       set_variable=true --example for setting some game settings only true while key is held down
    end
    
    function  on_release(event)
       set_variable=false --example for setting some game settings only true while key is held down ... which will be undone here
    end
    
    script.on_event("my_key", on_press)
    script.on_event(defines.events.on_keyup("my_key), on_release)

Re: [0.13.x +] Mod API: Add KeyUp Event

Posted: Wed Jul 06, 2016 9:08 pm
by ssilk
Moved from Suggestions to Modding Interface Requests

Re: [0.13.x +] Mod API: Add KeyUp Event

Posted: Sun Jan 14, 2018 11:29 pm
by ownlyme
This is a great idea.
It would add support for various controlling assists
- PavementDriveAssist could accelerate cars again when passing a speedlimit derestriction sign.
- I could make a mod that lets you control vehicles like the player character
and probably many more.

Re: [0.13.x +] Mod API: Add KeyUp Event

Posted: Mon Jan 15, 2018 4:35 am
by Rseding91
The way Factorio input works the game has no concept of keys. All it knows is some series of actions happened and now it has a piece of data that says "build blueprint". If that was triggered by left mouse button, a random key on the keyboard, or done programatically it has no idea.

Because of that there is no way to say "a key was released" because the game doesn't record the state of every key. If it did, the network traffic in multiplayer would be *much* higher with literally every key press generating a packet (or multiple packets in some cases).

Re: [0.13.x +] Mod API: Add KeyUp Event

Posted: Tue Jan 16, 2018 1:07 am
by eradicator
Rseding91 wrote:Because of that there is no way to say "a key was released" because the game doesn't record the state of every key. If it did, the network traffic in multiplayer would be *much* higher with literally every key press generating a packet (or multiple packets in some cases).
Imho some (any) way to make "hold key down" type input events moddable has great potential. Base game alreadyâ„¢ uses this behavior for left mouse clicks, space bar, WASD, etc.

A multi-purpose event to read all keyboard input isn't required either. It would be sufficent to be able to subscribe custom hotkeys to key_up type events instead of key_down. Or to have up/down as part of the event fired by any custom hotkey. A seperate subscription would mean that there's no additional network traffic unless a mod explicitly adds a prototype for it.