Can I do a call to a keyboard press?

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

    437 Posts


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

    2331 Posts

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

    Great Poster

    437 Posts

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

    but it didnt work

    Great Poster

    437 Posts

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

    Great Poster

    437 Posts

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

    Great Poster

    437 Posts

  • #7, by afrlmeSunday, 18. March 2018, 11:59 2 years ago
    you can print out keycodes, characters, specials, etc in the key event handler script.

    print(keycode, character)
    1


    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
    1
    2
    3
    4
    5
    6
    7
    8
    9



    Imperator

    6771 Posts

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

    Great Poster

    437 Posts

Write post