Keypress or Wait?

Keypress or Wait?

Discuss Lua based Spring scripts (LuaUI widgets, mission scripts, gaia scripts, mod-rules scripts, scripted keybindings, etc...)

Moderator: Moderators

Post Reply
User avatar
Stealth870
Posts: 166
Joined: 13 Sep 2004, 00:25

Keypress or Wait?

Post by Stealth870 »

Is there a way to detect in code if a key was pressed?

Also, what is the best way to have your code "wait" for something. Trying to work on my Ferry widget again and at the moment I have it so that your transport is put on Wait, and you start Shift+Right Clicking to create the waypoints. When I'm done doing that, hitting W will activate the rest of the ferry actions (stop waiting, convert last point to unload zone, add load zone at current position, repeat). But I don't know of how to have my widget wait till I'm done. I think the last time I used a while() loop I froze something. Is there a proper way to either detect if they key is pressed, or perhaps if the unit started moving (while speed is not 0)?
User avatar
Argh
Posts: 10920
Joined: 21 Feb 2005, 03:38

Re: Keypress or Wait?

Post by Argh »

Is there a way to detect in code if a key was pressed?
Yes, and it's easy to use, here's an example from P.U.R.E.:

Code: Select all

function widget:KeyPress(key, mods, isRepeat)
  if (key == KEYSYMS.ESCAPE) then

     Do Stuff Here.

  end
end
User avatar
Stealth870
Posts: 166
Joined: 13 Sep 2004, 00:25

Re: Keypress or Wait?

Post by Stealth870 »

Ok, awesome. Where can I find a list for all the keycodes?
imbaczek
Posts: 3629
Joined: 22 Aug 2006, 16:19

Re: Keypress or Wait?

Post by imbaczek »

in the KEYSYMS table. look at its keys.
Post Reply

Return to “Lua Scripts”