I have a simple quality-of-live mod (https://mods.factorio.com/mod/Blink) that teleports you in a certain direction with shift or control-WASD. I made it since I got down to ~15 UPS with my first megabase and running was.. Painful. I've had a very good suggestion to make this mod work when the key is held down - i.e shift-D held down makes you keep teleporting south until you release it. Looking for a keypress wasn't hard to figure out, but I can't find any way to detect when a key is held down to repeat the action. Anyone have any advice? Thanks!
- Jason
Detect when a key is held down
-
- Inserter
- Posts: 23
- Joined: Wed Jan 03, 2018 4:44 am
- Contact:
Re: Detect when a key is held down
There are no key down events. The best you can do is make one button to start teleporting in a direction, and one button to stop. Then do the teleporting in on_tick() depending on which was pressed last.
You could also hijack the player controls by checking character.walking_state every tick, which does update on key down.
You could also hijack the player controls by checking character.walking_state every tick, which does update on key down.
-
- Inserter
- Posts: 23
- Joined: Wed Jan 03, 2018 4:44 am
- Contact:
Re: Detect when a key is held down
Thank you very much for the rapid reply!
You know, that makes me think of something.. I've always wanted a way to "run and keep running" with one keypress. Before I did the Blink mod, running a distance required constantly holding the key down and you can't switch to another window while looking something up on a long run. Would it be possible to build an always-run function (i.e. alt+w to run north until any other button is pressed) with what you are describing?
You know, that makes me think of something.. I've always wanted a way to "run and keep running" with one keypress. Before I did the Blink mod, running a distance required constantly holding the key down and you can't switch to another window while looking something up on a long run. Would it be possible to build an always-run function (i.e. alt+w to run north until any other button is pressed) with what you are describing?
Re: Detect when a key is held down
Yes, character.walking_state is writable, so you can automate running by updating it every tick.
Re: Detect when a key is held down
I found out recently that my programmable keypad (from allreli) can be programmed to do this.
I just created a macro that pressed and released a key and then deleted the keyup event in the recorded macro.
I suppose any programmable keyboard can do this. (Unfortunately the allreli keypad is no longer available.)
You might also be able to do this with autohotkey.
I just created a macro that pressed and released a key and then deleted the keyup event in the recorded macro.
I suppose any programmable keyboard can do this. (Unfortunately the allreli keypad is no longer available.)
You might also be able to do this with autohotkey.
- eradicator
- Smart Inserter
- Posts: 5211
- Joined: Tue Jul 12, 2016 9:03 am
- Contact:
Re: Detect when a key is held down
Years ago i tried on_tick'ing walking_state in multiplayer and concluded that (probably due to lag hiding) it produces erratic laggy walking.
Trivially! I.e. "press shift+w to hold down w until w is pressed again."
Code: Select all
+w::Send, {w down}
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.
Mod support languages: 日本語, Deutsch, English
My code in the post above is dedicated to the public domain under CC0.