Keyboard and values

For questions about using Classic.

Post » Wed May 13, 2009 7:24 pm

Hi everyone ! :D
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.
B
8
S
4
G
5
Posts: 32
Reputation: 2,816

Post » Wed May 13, 2009 7:54 pm

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
Spriter Dev
B
87
S
21
G
12
Posts: 3,240
Reputation: 16,461

Post » Wed May 13, 2009 8:01 pm

[quote="lucid":2gipzvtc]you can check if a key is down and don't need to remember a number, you can just choose which key[/quote:2gipzvtc]

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?
Moderator
B
5
S
2
G
6
Posts: 4,348
Reputation: 10,971

Post » Wed May 13, 2009 8:46 pm

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 :wink:

As what I want to do doesn't seem easily possible, should I add it to the Feature Requests ?
B
8
S
4
G
5
Posts: 32
Reputation: 2,816

Post » Wed May 13, 2009 9:39 pm

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.
Moderator
B
5
S
2
G
6
Posts: 4,348
Reputation: 10,971

Post » Wed May 13, 2009 9:53 pm

the workaround is simple actually
I didn't realize it before I last posted, but here it is:

[url:3c8mr52t]http://dl.getdropbox.com/u/1013446/lastkeypressed.cap[/url:3c8mr52t]

all you do is one event with a loop

[code:3c8mr52t]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
Spriter Dev
B
87
S
21
G
12
Posts: 3,240
Reputation: 16,461

Post » Wed May 13, 2009 11:36 pm

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
B
4
S
2
G
6
Posts: 161
Reputation: 2,597

Post » Thu May 14, 2009 12:14 am

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.
B
2
G
3
Posts: 15
Reputation: 880

Post » Thu May 14, 2009 12:44 am

[quote="revolther":3pdukfh0]
Things would be quite simplified with the For each object scenario, if you could reference "This" afterwards as well. [/quote:3pdukfh0]

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
Spriter Dev
B
87
S
21
G
12
Posts: 3,240
Reputation: 16,461

Post » Thu May 14, 2009 12:54 am

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)

[url:3kw781zy]http://dl.getdropbox.com/u/1013446/lastkeypressed.cap[/url:3kw781zy]
Spriter Dev
B
87
S
21
G
12
Posts: 3,240
Reputation: 16,461

Next

Return to Help & Support using Construct Classic

Who is online

Users browsing this forum: No registered users and 3 guests