Login / Registrieren
DE EN FR ES IT CZ
Zurück Nach oben

Can I do a call to a keyboard press?

  • #1, by AkcayKaraazmak 8 years ago Zitieren
    Can I call keypress function for a key I select? When navigating the character with WASD, if the character enters an actionarea that have the code "changeScene" and after it loads, the character goes to that action area again, even the mouse click doesnt stop it, just it stops if I press WASD. I think it's a bug. So I thought if I call (press) a key W, A,S or D or arrow keys from the code (execute script) then character won't go to the actionarea after changeScene,

    Weird but it could be a solution smile
  • #2, by sebastian 8 years ago Zitieren
    Hi Akcay,

    Use the "createEvent()" function to simulate keypress:

    the keycode in the example (eKeyEscape) needs to be replaced with the keycode for your WASD keys i guess. 
  • #3, by AkcayKaraazmak 8 years ago Zitieren
    Thank you mate, so if I will just write createEvent( "eEvtKeyDown", { x = 0, y = 0 }, eEvtKeyDown, 0 ) in executeascript Action?
  • #4, by AkcayKaraazmak 8 years ago Zitieren
    I wrote in "execure  script" -> " createEvent( "eEvtKeyDown", { x = 0, y = 0 }, 1000001, 0 ) "

    but it didnt work
  • #5, by AkcayKaraazmak 8 years ago Zitieren
    I used this one " createEvent( "eEvtKeyDown", { x = 0, y = 0 }, eKeyA, 0 ) " and it worked mate! Thank you so much!
  • #6, by AkcayKaraazmak 8 years ago Zitieren
    Ovv no it was my mistake, it didnt work :\ ... Where I can find the keycodes of wasd and arrow keys?
  • #7, by afrlme 8 years ago Zitieren
    you can print out keycodes, characters, specials, etc in the key event handler script.

    print(keycode, character)


    I think arrow keys are eKeyLeft, eKeyRight, eKeyUp, eKeyDown because they are special characters just like eKeyEscape. They might require Arrow on the end though like eKeyLeftArrow - I forget. You can also check if they are x keycode instead too.

    Regular characters (letters & numbers) you can check with...
    if character == "w" then
     -- do something
    elseif character == "a" then
     -- do something
    elseif character == "s" then
    -- do something
    elseif character == "d" then
     -- do something
    end



  • #8, by AkcayKaraazmak 8 years ago Zitieren
    Thank you so much Lee, I'll try it