1. Hey! Guest! The 33rd GMC Jam will take place between May 23rd, 12:00 UTC (Friday noon) and May 27th, 12:00 UTC (Monday noon). Why not join in! Click here to find out more!
    Dismiss Notice

GML Tapping Keys without Holding [SOLVED]

Discussion in 'Programming' started by Patrick Johnson, May 17, 2019 at 7:26 PM.

  1. Patrick Johnson

    Patrick Johnson Member

    Apr 14, 2018
    Hey all,

    I need some help with keyboard tapping.

    What I want to do:
    Quickly Tap the space key on a keyboard to launch the start menu
    Quickly Tap the space key on a keyboard again to close the start menu

    What I have figured out already:
    How to execute/stop the script itself

    What I have tried (but isn't working):
    button timers in association with keyboard checks

    Right now all I can figure out is to hold the key to keep the script running. keyboard_check/_pressed/_released doesn't seem to work the way I want it to. I can only hold the key down to keep it open, and it closes once I release the key. I know the solution is probably simple but I'm scratching my head over it.

    Help is much appreciated!

  2. samspade

    samspade Member

    Feb 26, 2017
    You'll have to code key tapping yourself. Fortunately, it isn't hard. The logic is this:
    • When key is held, count up
    • When key is released, check to see if value is less than the tap length you want
    • if it is, do something
    • either way reset variable to 0

    ///step event
    if (key_held) {
        key_held_time += 1;
    } else if (key_released) {
        if (key_held_time <= tap_length) {
            //you've tapped
        key_held_time = 0;
    It doesn't need to be done exactly that way (e.g. you could put it in a key pressed event, you could use the built in alarms - starting it on key pressed, and so on) but the logic is the same regardless.
  3. Taddio

    Taddio Member

    Nov 16, 2018
    So you want the menu to open when yyou press a key. Then it stays open until you press it again without needing to hold it down, right?

    How I usually tackle that is using a flag for the menu, e.g. (in create event)
    menu_is_open = false;
    Then in Key Pressed event:
    menu_is_open = !menu_is_open;
    //Will trigger on/off the menu 
    And finally, in some obj_menu, obj_controller, or something like that:
    if(menu_is_open) {
        //Draw the menu and all the stuff related to it
    Hope that's what you were looking for!
  4. Patrick Johnson

    Patrick Johnson Member

    Apr 14, 2018
    I got it working! I wasnt using the key_check_pressed event properly. Thanks all.

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice