Can I do a call to a keyboard press?

  • #1, by AkcayKaraazmakSaturday, 17. March 2018, 22:31 6 years ago
    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

    Great Poster

    440 Posts


  • #2, by sebastianSaturday, 17. March 2018, 23:02 6 years ago
    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. 

    Thread Captain

    2346 Posts

  • #3, by AkcayKaraazmakSaturday, 17. March 2018, 23:11 6 years ago
    Thank you mate, so if I will just write createEvent( "eEvtKeyDown", { x = 0, y = 0 }, eEvtKeyDown, 0 ) in executeascript Action?

    Great Poster

    440 Posts

  • #4, by AkcayKaraazmakSaturday, 17. March 2018, 23:18 6 years ago
    I wrote in "execure  script" -> " createEvent( "eEvtKeyDown", { x = 0, y = 0 }, 1000001, 0 ) "

    but it didnt work

    Great Poster

    440 Posts

  • #5, by AkcayKaraazmakSaturday, 17. March 2018, 23:32 6 years ago
    I used this one " createEvent( "eEvtKeyDown", { x = 0, y = 0 }, eKeyA, 0 ) " and it worked mate! Thank you so much!

    Great Poster

    440 Posts

  • #6, by AkcayKaraazmakSunday, 18. March 2018, 01:23 6 years ago
    Ovv no it was my mistake, it didnt work :\ ... Where I can find the keycodes of wasd and arrow keys?

    Great Poster

    440 Posts

  • #7, by afrlmeSunday, 18. March 2018, 11:59 6 years ago
    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



    Imperator

    7278 Posts

  • #8, by AkcayKaraazmakSunday, 18. March 2018, 14:25 6 years ago
    Thank you so much Lee, I'll try it

    Great Poster

    440 Posts