Just one action when key is pressed

Posted By: Tiles

Just one action when key is pressed - 11/03/07 09:26

I try to toggle the overlay | visible flags of a panel with pressing the F11 key. if key_f11 causes the panel to toggle all the time when pressing the key. Next way leaded to the manual where i couldn't find my needed info.
on_f11 = toggle(panDisplay2,VISIBLE); just crashes ...

And so i ended in this construct:

Code:
 
var keyblock;

void main ()
{
...
while (1)
{
if ((key_f11) && (keyblock == 0))
{
toggle(panDisplay2,VISIBLE);
toggle(panDisplay2,OVERLAY);
toggle(panDisplay,VISIBLE);
toggle(panDisplay,OVERLAY);
keyblock = 1;
}
if ((key_f11 == 0) && (keyblock == 1))
{
keyblock = 0;
}
}
...
}



Well, it works. But for me it seems an enourmous effort to implement a keyblocker var for every possible key. Is there a better way to do what i want?
Posted By: hack-panther

Re: Just one action when key is pressed - 11/03/07 09:49

Maybe like this?

Code:
 
void main ()
{
...
while (1)
{
if ((key_f11))
{
toggle(panDisplay2,VISIBLE);
toggle(panDisplay2,OVERLAY);
toggle(panDisplay,VISIBLE);
toggle(panDisplay,OVERLAY);
while((key_f11)) wait(1);
}
wait(1);
}
...
}


Posted By: Tiles

Re: Just one action when key is pressed - 11/03/07 09:54

Excellent. I knew there is a better way. Thanks
Posted By: msl_manni

Re: Just one action when key is pressed - 11/03/07 10:18

on_f11 = toggle(panDisplay2,VISIBLE); just crashes ...


change it to

on_f11 = toggle;

then it wont crash.
Posted By: Tiles

Re: Just one action when key is pressed - 11/03/07 12:07

Indeed. No crash. But it doesn't toggle, because now it doesn't know what to toggle. And gives me an syntax error too, not starting at all
Posted By: Tiles

Re: Just one action when key is pressed - 11/03/07 12:26

Ah, me idiot. on_key is a function call without the use of (), right? No wonder i didn't get it to work. I expected a () for a function call ...

Okay, got the syntax error sorted too. Gave me an error because toggle is reserved by the engine (grr, everything you need is always reserved, and so you cannot use for what you really need it). Using another word like toggl solved it

So i have two working ways now. Thanks for your help

EDIT: Wow, lots of pitfalls here. on_f11 overrides the default.c f11 functions. And so the default values and the wire doesn't show anymore. So i have to use the if (key_f11) for my case here.
Posted By: FBL

Re: Just one action when key is pressed - 11/04/07 10:30

Use another key for testing and change it to F11 for the finished product

Or take acknex.c, copy it locally and adapt it to your needs.
Posted By: Tiles

Re: Just one action when key is pressed - 11/04/07 12:06

Will do. Danke
© 2024 lite-C Forums