QB64 Phoenix Edition
Question about _KeyDown - Printable Version

+- QB64 Phoenix Edition (https://qb64phoenix.com/forum)
+-- Forum: QB64 Rising (https://qb64phoenix.com/forum/forumdisplay.php?fid=1)
+--- Forum: Code and Stuff (https://qb64phoenix.com/forum/forumdisplay.php?fid=3)
+---- Forum: Help Me! (https://qb64phoenix.com/forum/forumdisplay.php?fid=10)
+---- Thread: Question about _KeyDown (/showthread.php?tid=3039)



Question about _KeyDown - Kernelpanic - 09-16-2024

Why doesn't this work (program termination)?  Huh

Code: (Select All)

Dim As Integer zahl

Do
  Input "Zahl: ", zahl
Loop Until _KeyDown(27) 'ESC

I found it here: https://qb64phoenix.com/forum/showthread.php?tid=3037&pid=28453#pid28453


RE: Question about _KeyDown - DSMan195276 - 09-16-2024

How are you trying to use it? "Input" blocks execution of the program at that point until the Input statement is done. Meaning, for the _keydown to trigger you need to be holding ESC down before hitting Enter to end the Input statement. Otherwise it just loops once and blocks on Input again before you can ever press ESC.


RE: Question about _KeyDown - TerryRitchie - 09-16-2024

DO
    INPUT "Number: ", n!
LOOP UNTIL _KEYDOWN(27)

The loop above can never be terminated because in order to leave the INPUT statement you must press ENTER.

DO
    INPUT "Number: ", n!
LOOP UNTIL n! = 0

The loop above can terminate because it relies on the value of n!


RE: Question about _KeyDown - Kernelpanic - 09-16-2024

Thanks for the answers!

DSMan195276, yes, that's right! It would be a good notice in the wiki for KeyDown

Terry, I know that one can end the loop in another way, but this about KeyDown was unknown me.


RE: Question about _KeyDown - Pete - 09-16-2024

Oh just write a custom keyboard input routine you lazy varmint!

or...

Code: (Select All)
Do
    Input a
    Sleep 1
Loop Until _KeyDown(27)

Now you don't need no stinkin' null value... but ya gotta be quick!

Pete Big Grin Big Grin Big Grin


RE: Question about _KeyDown - TerryRitchie - 09-16-2024

(09-16-2024, 07:53 PM)Pete Wrote: Oh just write a custom keyboard input routine you lazy varmint!

or...

Code: (Select All)
Do
    Input a
    Sleep 1
Loop Until _KeyDown(27)

Now you don't need no stinkin' null value... but ya gotta be quick!

Pete Big Grin Big Grin Big Grin
It looks like you just won the award you were fretting about in another post. Big Grin

(09-16-2024, 07:44 PM)Kernelpanic Wrote: Thanks for the answers!

DSMan195276, yes, that's right! It would be a good notice in the wiki for KeyDown

Terry, I know that one can end the loop in another way, but this about KeyDown was unknown me.
In lesson 7 of the tutorial I cover all the different methods of using keyboard input.

https://www.qb64tutorial.com/lesson7

And then in lesson 21 I cover the _DEVICES and _BUTTON statements and how they can be used as keyboard inputs as well.

https://www.qb64tutorial.com/lesson21

When you get a chance check them out. Lots of good stuff in there.


RE: Question about _KeyDown - Kernelpanic - 09-16-2024

Quote:Oh just write a custom keyboard input routine you lazy varmint! 
Good too. But quickly . . . There is strength in calmness! - Hmm, was that Platon or Caesar or Kant? Maybe it was Taylor Swift.  Rolleyes



Code: (Select All)

Do
  Input a
  Sleep 10
Loop Until _KeyDown(27)



RE: Question about _KeyDown - Pete - 09-16-2024

10 seconds to make up your mind? No wonder the Germans lost WWII!

Now if you will excuse me, Steve's on his way over to take my award photo!

Pete Big Grin