Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Question about _KeyDown
#1
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...3#pid28453
Reply
#2
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.
Reply
#3
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!
New to QB64pe? Visit the QB64 tutorial to get started.
QB64 Tutorial
Reply
#4
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.
Reply
#5
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
Shoot first and shoot people who ask questions, later.
Reply
#6
(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.
New to QB64pe? Visit the QB64 tutorial to get started.
QB64 Tutorial
Reply
#7
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)
Reply
#8
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
Shoot first and shoot people who ask questions, later.
Reply




Users browsing this thread: 8 Guest(s)