Checking if no key is pressed

This forum is currently in read-only mode.
From the Asset Store
Random Maze Generator with Door & Key System - tutorial capx
  • Is there a way to check whether no key is being pressed? I want the game to check if the player isn't pressing any key at all. The regular keyboard and mouse object only includes a condition for any key being pressed. I tried using that and inverting the condition, but it doesn't seem to work. Does anyone how to do this?

    Thanks.

  • Unfortunately the "on any key pressed/released" are triggers, meaning they only happen once when first "triggered", so inverse of that is something that never happens at all.

    It looks like you might have to check "is down" for each and every control to check for no keys down sadly

  • you could use a global variable and a loop. something like:

    every tick

    --- set global 'anykeydown' to 0

    for "" from 0 to 255

    key loopindex is down?

    --- set global 'anykeydown' to 1

    global 'anykeydown' equal to 0

    --- do stuff

  • Hi guys,

    I just wanted to present an alternative to the great R0j0's suggestion. Seems lighter and uses base events instead of code which makes it easier for some people to understand.

    Set Global Variable: Idle_Counter = 200
    
    Keyboard: on any key pressed 
    ->  Set Idle_Counter to 200
    
    Every 0.1 seconds
    -> IF Idle_Counter<=0
    ->->Set Idle_Counter to 200
    ->->...and whatever actions you wish to perform
    [/code:1y79ga94]
    
    The reason why I reset the variable in the last part is because I'm using it to recall a layout which doesn't reset the variable at start.
    I'm using "Every 0.1 seconds" instead of "Every tick" to reduce processor usage.
  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • vila4480

    Why post in a 2 year old Construct Classic thread, using an example not even using CC - your example is likely C2.

  • vila4480

    Why post in a 2 year old Construct Classic thread, using an example not even using CC - your example is likely C2.

    Terribly sorry - I noticed the thread was old but the issue still current.

    I didn't notice it was Construct Classic and for that I apologise!

  • hi. use a screen reader jaws for windows from freedomscientific.com and non visual desktop access from nvaccess.org. and now using construct 2, version 295, windows 10 64 bit pro free version. now is there a keyboard short cut to get to the browse button. can insert objects, and have to use my screen reader mouse cursur, to then use caps lock and 8 on the keyboard to left and 9 for right click, and then press the applications key, and then the menus. and then insert new object, and then able to then edit the name of the object, but no way to then find the browse button to then import images, backgrounds. etc. so is there a keyboard short cut. looked in themanual and the keybord section. will alt b do this and turn it on or off. so any blind developers here, and cannot use the mouse, erratic with a screen reader. any ideas. thanks.Hi guys,

    I just wanted to present an alternative to the great R0j0's suggestion. Seems lighter and uses base events instead of code which makes it easier for some people to understand.

    Set Global Variable: Idle_Counter = 200
    
    Keyboard: on any key pressed 
    ->  Set Idle_Counter to 200
    
    Every 0.1 seconds
    -> IF Idle_Counter<=0
    ->->Set Idle_Counter to 200
    ->->...and whatever actions you wish to perform
    [/code:24ehl5ix]
    
    The reason why I reset the variable in the last part is because I'm using it to recall a layout which doesn't reset the variable at start.
    I'm using "Every 0.1 seconds" instead of "Every tick" to reduce processor usage.
Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)