Keyboard and values

This forum is currently in read-only mode.
From the Asset Store
Total customisation of the input! You can combine inputs from all peripherals. Make your game accessible for everyone!
  • Hi everyone !

    I'm new to Construct, but I've been using MMF2 before (like many members here I guess). I'll go on a more detailed presentation if you want it, but now I've got a question.

    MMF2 has a quite useful object, "Control X", which allows to retrieve the last pressed key and to check whether a particular key is pressed, using values. For instance, the Space key is associated to 32, and you can add conditions to test if the key 32 is down.

    Is there a way to do this using Construct?

    The Mouse & Keyboard doesn't let me write an expression when I want to test whether a key is down, it just includes a menu. And I didn't find any way to retrieve the last pressed key as a value.

    Thanks in advance and sorry if the question was already posted somewhere.

  • you can check if a key is down and don't need to remember a number, you can just choose which key

    but I'm not sure the operation you're talking about is built into mouse/keyboard, however is easy to implement, if you already have events for the keypresses. do you just want to know if they press anything on the keyboard?, or the last key they used that is a set key in your game?

    like if they pressed space, which is the fire button down last.

    if it's just controls, then in the events that catch the button presses, you just set a global or private variable to whatever control you're in the event for

    it's possible to test for any key, but it's more complicated than just making events for specific keys

  • you can check if a key is down and don't need to remember a number, you can just choose which key

    He means he wants to use an expression to check which key is pressed, not just pick a herd-coded key from a drop-down list.

    And unfortunately, no, though it would be useful there's no way to check for dynamic key input yet (at least, not easily. You could create your own complex, custom workaround, however).

    I assume you're wanting some sort of custom controls setup, where you can store a key value in a variable and use that as a compare condition in an event?

  • Lucid : I would like it to work with any keys.

    Deadeye : That's it. The only workaround I've found is adding a "control" for every possible key (in the Manage Controls window of the application properties) and then use the "Control is down?" condition, which allows an expression to be entered. But that's really tedious and don't allow to check what is the last pressed key (unless I add like 200 events to test for each key).

    And yes, I'd like to make a custom controls setup in my game, exactly what you said

    As what I want to do doesn't seem easily possible, should I add it to the Feature Requests ?

  • I believe setting custom controls at runtime is a goal for v1.0, but getting the value of a key, and comparing an arbitrary value to a keypress event are a bit different and would have other practical uses as well, so I say yeah, go ahead and make a request.

    That is, if it hasn't already been made. I'd search around a but first.

  • the workaround is simple actually

    I didn't realize it before I last posted, but here it is:

    http://dl.getdropbox.com/u/1013446/lastkeypressed.cap

    all you do is one event with a loop

    for loop 0 thru 255
    ---on key [loopindex] pressed[/code:3c8mr52t]
    
    to set the key to loopindex, you have to right click where you choose a key, and click Use Expression
    
    when this event is triggered, loopindex is the numeric value of the key pressed
    
    and it's easy from there to set global variables
    and use expressions again to choose your key
    on key global('up key') pressed
    
    fun stuff
    I love construct
  • On the topic of keyboard values, given the popular trend of WASD movement controls in Construct, I am for changing the key detection to something based on key location rather than visual identity. Not everyone uses qwerty and azerty, you know?

    To clarify, ',aoe' is my 'wasd', but I know there is a way to make applications register key presses based on their location rather than their character value.

    edit: key scan codes? http://en.wikipedia.org/wiki/Scancode

  • The Wiki, talks about the use of "This" to reference things referenced in system processes, and things like this scenario are exactly what you would think it would apply to, however it has next to no use I've found.

    Things would be quite simplified with the For each object scenario, if you could reference "This" afterwards as well.

    The cpu stores all these things temporarily, however I've found no way to access them, it's quite frustrating.

  • Things would be quite simplified with the For each object scenario, if you could reference "This" afterwards as well.

    when you do

    for each object

    it picks the objects one by one

    so if you say

    for each sprite

    -----set sprite.x to loopindex

    it will give each sprite a different value

    you don't need this because you can just refer to the object by name and you're always only talking about the one it's currently on

  • OOPS, just realized the wrong thing was saved to dropbox

    here it is

    the basis for setting custom keys (other link should work now as well)

    http://dl.getdropbox.com/u/1013446/lastkeypressed.cap

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • OOPS, just realized the wrong thing was saved to dropbox

    here it is

    the basis for setting custom keys (other link should work now as well)

    http://dl.getdropbox.com/u/1013446/lastkeypressed.cap

    Holy... whoa

    Shows what I know

  • I wish I had know about using expressions for keyboard input before. Thanks for pointing that out, lucid.

  • Thanks for the helpful answers everyone.

    And thank you Lucid for the cap file, and telling about the "use expression" option, I don't think I would have find it

  • no problem guys,

    there's alot of weird stuff you can do with the "use expression" thing

    hope it comes in handy

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)