GMS 2 get current key pressed?

Discussion in 'Programming' started by Shadowblitz16, Jul 10, 2019 at 10:27 PM.

  1. Shadowblitz16

    Shadowblitz16 Member

    Joined:
    Jun 23, 2016
    Posts:
    594
    is there a way to get the currently pressed keyboard key by looping through keys?

    something similar to what this does for the gamepad..
    Code:
    for ( var i = gp_face1; i < gp_axisrv; i++ ) 
    {
        if ( gamepad_button_check( 0, i ) ) return i;
    }
    return false;
    
    I don't want to use keyboard_lastkey because that would continue to check every frame.
     
  2. SoVes

    SoVes Member

    Joined:
    May 17, 2017
    Posts:
    132
    can't you do something like so it would only trigger that frame
    Code:
    if keyboard_check_pressed(vk_anykey){
    var current_key = keyboard_lastkey;
    }
     
    Shadowblitz16 likes this.
  3. Shadowblitz16

    Shadowblitz16 Member

    Joined:
    Jun 23, 2016
    Posts:
    594
    that works thankyou!
     

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