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

Things that we aren't going to implement
Bizz Keryear
Long Handed Inserter
Long Handed Inserter
Posts: 91
Joined: Thu Oct 22, 2015 5:08 am
Contact:

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

Post 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)
User avatar
ssilk
Global Moderator
Global Moderator
Posts: 12889
Joined: Tue Apr 16, 2013 10:35 pm
Contact:

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

Post by ssilk »

Moved from Suggestions to Modding Interface Requests
Cool suggestion: Eatable MOUSE-pointers.
Have you used the Advanced Search today?
Need help, question? FAQ - Wiki - Forum help
I still like small signatures...
User avatar
ownlyme
Filter Inserter
Filter Inserter
Posts: 426
Joined: Thu Dec 21, 2017 8:02 am
Contact:

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

Post 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.
creator of 52 mods
My requests: relAbove||Grenade arc||Blueprint allies||Creeps forget command/ don't get removed||Player Modifiers||textbox::selection||Better Heat IF||Singleplayer RCON||tank bug w/ min_range >= projectile_creation_distance
Rseding91
Factorio Staff
Factorio Staff
Posts: 14601
Joined: Wed Jun 11, 2014 5:23 am
Contact:

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

Post 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).
If you want to get ahold of me I'm almost always on Discord.
User avatar
eradicator
Smart Inserter
Smart Inserter
Posts: 5211
Joined: Tue Jul 12, 2016 9:03 am
Contact:

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

Post 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.
Author of: Belt Planner, Hand Crank Generator, Screenshot Maker, /sudo and more.
Mod support languages: 日本語, Deutsch, English
My code in the post above is dedicated to the public domain under CC0.
Post Reply

Return to “Won't implement”