Gamestudio Links
Zorro Links
Newest Posts
New FXCM FIX Plugin
by flink. 06/04/24 07:30
AlpacaZorroPlugin v1.3.0 Released
by kzhao. 05/22/24 13:41
Free Live Data for Zorro with Paper Trading?
by AbrahamR. 05/18/24 13:28
Change chart colours
by 7th_zorro. 05/11/24 09:25
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
0 registered members (), 1,459 guests, and 9 spiders.
Key: Admin, Global Mod, Mod
Newest Members
AemStones, LucasJoshua, Baklazhan, Hanky27, firatv
19058 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
detect when a key is released #337280
08/09/10 21:29
08/09/10 21:29
Joined: Jan 2010
Posts: 23
D
Darkmax Offline OP
Newbie
Darkmax  Offline OP
Newbie
D

Joined: Jan 2010
Posts: 23
hi i a newbie in game studio, im having trouble finding a easy thing like detect the state of a key, for example i want to run a function when i released the space key.

for example i want to turn a light on or off when the user press space but just when he release it, because if he keeps pressing down the key the function is calling a lots of times.

So how i detect when i released the key pressed?

Re: detect when a key is released [Re: Darkmax] #337287
08/09/10 22:18
08/09/10 22:18
Joined: Jun 2009
Posts: 2,210
Bavaria, Germany
Kartoffel Offline
Expert
Kartoffel  Offline
Expert

Joined: Jun 2009
Posts: 2,210
Bavaria, Germany
that's simple:

on_space=light_on;

IMPORTANT: when using the on_... (on_enter,on_f1 (that works for every key))
the function (in this case) light_on will just called once if you press the key. So you don't have the problem, that the function will called more than once per keypress.
and you just have to call it once, or if you want to bind the key to another function. And you can't use brackets: on_space=light_on(); doesn't work

i hope this helps you

Kartoffel


POTATO-MAN saves the day! - Random
Re: detect when a key is released [Re: Kartoffel] #337292
08/09/10 22:54
08/09/10 22:54
Joined: May 2007
Posts: 2,043
Germany
Lukas Offline

Programmer
Lukas  Offline

Programmer

Joined: May 2007
Posts: 2,043
Germany
AFAIK on_space is called each frame while space is pressed, not only once.

I'd do something like this:
while(!key_space) wait(1);
turn_the_light_on();
while(key_space) wait(1);
turn_the_light_off();

Re: detect when a key is released [Re: Lukas] #337820
08/13/10 18:28
08/13/10 18:28
Joined: Aug 2007
Posts: 1,922
Schweiz
Widi Offline
Serious User
Widi  Offline
Serious User

Joined: Aug 2007
Posts: 1,922
Schweiz
on_space is called only one.
key_space is called every frame wink

Re: detect when a key is released [Re: Widi] #337844
08/13/10 21:34
08/13/10 21:34
Joined: Jul 2008
Posts: 1,178
England
M
MrGuest Offline
Serious User
MrGuest  Offline
Serious User
M

Joined: Jul 2008
Posts: 1,178
England
Code:
void toggle_switch(){
   while(key_space){ wait(1); }
   //turn off switch here
}

void main(){

   ...
   on_space = toggle_switch;
   ...
}



Re: detect when a key is released [Re: MrGuest] #337869
08/14/10 00:13
08/14/10 00:13
Joined: Oct 2007
Posts: 5,210
İstanbul, Turkey
Quad Offline
Senior Expert
Quad  Offline
Senior Expert

Joined: Oct 2007
Posts: 5,210
İstanbul, Turkey
@widi key_space is not a function it's a variable


3333333333
Re: detect when a key is released [Re: Quad] #337888
08/14/10 07:30
08/14/10 07:30
Joined: Aug 2000
Posts: 1,140
Baunatal, Germany
Tobias Offline

Moderator
Tobias  Offline

Moderator

Joined: Aug 2000
Posts: 1,140
Baunatal, Germany
You can also use key_hit for detecting the moment when the key is pressed down, thats in the keys.c library.

if(key_hit("a")) ....

is different to

if(key_a) ...

which is true as long as the key is pressed down.


Moderated by  HeelX, Lukas, rayp, Rei_Ayanami, Superku, Tobias, TWO, VeT 

Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1