Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
_Keyhit is devilishly evil ... here's why (warning)
#1
Tried doing a little program.  Wanted to use the cursor keys as movement (left, right, up and down) followed by enter when done.  _Inkey$ wasn't going to work for me.
Came upon _Keyhit.  A value is returned as key codes.  Nice. Until I used it.

Grab a key code input: (Q would abort the program)
        Do
            _Limit 5
            x = _KeyHit
            If x = 81 Or x = 113 Then End
            If x < 0 Then x = 0
            If x <> 0 Then Exit Do
        Loop

' do some wild and interesting things here based upon cursor keys, unimportant to the my problem.

' exiting here after the magic

' the main block code is executed twice once as a test run then the real thing

If testrun = 0 Then End

*** insert below code here to fix it ***

Input "hit enter to start the real run or anything to quit"; a$
If a$ = "" Then testrun = 0: GoTo reruntop

The above line is the last line of code.  Which would default "end" if anything is input except just enter.
The devilishly evil thing about _Keyhit, which I assumed and didn't realize.  It's nothing like Inkey$
_Keyhit returns key codes, but does not modify the keyboard buffer when a key code is observed.
aka: Schrödinger's cat is still in the box re:keyboard buffer.  Wither you looked or not.

Happy ending.  Do this before next input requirement:

Do
    a$ = InKey$
Loop Until a$ = ""

Happy trails. Big Grin
Reply


Messages In This Thread
_Keyhit is devilishly evil ... here's why (warning) - by doppler - 09-15-2024, 01:21 PM



Users browsing this thread: 1 Guest(s)