need delay while key not pressed |
Naith
|
Not sure I understand what you're trying to do. Explain a bit more what you're trying to achieve and I can try coming up with a solution for you.
|
|||||||||||
|
bilsch01
|
When the program reaches the 'while' line (below) I want it to enter the loop and stay there burning time (500 ms per loop cycle) until the 'L' key is pressed, at which time it exits the loop.
|
|||||||||||||||
|
bilsch01
|
The problem is it doesn't work. It never enters the loop.
|
|||||||||||
|
need delay while key not pressed |
Michael Fairley
Guest
|
I think you want the condition to be (!(event.type == SDL_KEYDOWN && event.key.keysym.scancode == SDL_SCANCODE_L)). As is, your condition is checking for events that happen to L key that aren't keydown.
On Sun, Jul 10, 2016 at 12:33 AM, bilsch01 wrote:
|
|||||||||||||
|
bilsch01
|
Thanks. That is the solution. But now I have another problem: When the program is in the delay loop it doesn't exit when 'L' is pressed. Then after about 4 seconds the screen dims down. I want the frozen display to stay to stay on the screen until the 'L' key is pressed, then continue execution.
Bill S. |
|||||||||||
|
need delay while key not pressed |
Jonny D
|
Your code enters a hard loop where it delays forever. Nothing changes any variable that would help the loop to end, so your OS is helpfully telling you there's a problem.
SDL can only change the 'event' variable if you give it control, say, in a function like SDL_PollEvent().  `event.key.keysym.scancode` will not magically change on its own. Use SDL_PollEvent() in your delay loop and then you'll be getting somewhere. Jonny D On Sat, Jul 9, 2016 at 7:38 PM, bilsch01 wrote:
|
|||||||||||||
|
bilsch01
|
Yes. I did that and I got it working how I want.
Thanks. Bill S. |
|||||||||||
|
Re: need delay while key not pressed |
bilsch01
|
How does my OS (ubuntu) know the situation inside the loop if the loop does something every 500 msec? That's not very often. |
|||||||||||||
|
need delay while key not pressed |
Jonny D
|
Well, I was interpreting what you said about dimming. On Windows, if you do not interact with the OS (e.g. no SDL_PollEvent() over a span of about 5 seconds, then the OS sees your program in an unresponsive state and prompts you to do something about it.
Jonny D On Sun, Jul 10, 2016 at 4:50 AM, bilsch01 wrote:
|
|||||||||||||
|