Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Ways to trap function key
#1
This is not a bug report but I was about to declare an error.

This code contains 2 ways to trap the F1 key:

The difference is between soft key and scan key when key is set
  (has nothing to do with Key On or Key Off)..

Code: (Select All)
' Ways to trap function keys.
f$ = "EDIT"
KEY 1, f$ ' activate soft key.
Print "Press F1:"
Do
   x$ = InKey$
   If Len(x$) Then
      q$ = q$ + x$
   Else
      If Len(q$) Then
         Exit Do
      End If
   End If
Loop
If q$ = f$ Then
   Print "F1 pressed. (equals:"; q$; ")"
End If
KEY 1, "" ' decativate soft key.
Print "Press F1:"
Do
   x$ = InKey$
   If x$ = Chr$(0) + Chr$(59) Then
      Print "F1 pressed. (equals:"; Asc(Right$(x$, 1)); ")"
      Exit Do
   End If
Loop
End
Reply
#2
Maybe I'm missing the point here, but I find it easiest to use the _keyhit funcion, which returns the value 15104 for example, for F1
Of all the places on Earth, and all the planets in the Universe, I'd rather live here (Perth, W.A.) Big Grin
Please visit my Website at: http://oldendayskids.blogspot.com/
Reply
#3
No worries Phil; I missed whatever point there was as well and thought the same as you.  _KeyHit is your friend!
Reply
#4
Don't think I ever used the Key method in Eric's first example. So it was news to me no matter long it's been around. Thanks Eric!

So that makes 4 ways to trap a key:
1. Inkey$
2. KeyHit
3. Keydown
4. Key

SmallBASIC had a way to associate a Key to a subroutine so that routine would execute when the Key was pressed, maybe ON KEY for us?

Just looked it up: Yes! On Key(1) would trap the F1 key and send you to a GoSub or Sub you setup on same command. Numbers 1-10 dedicated to Function keys then 11-14? the arrow keys, this old stuff probably came with QB4.5?
b = b + ...
Reply
#5
(01-20-2024, 02:01 PM)bplus Wrote: Don't think I ever used the Key method in Eric's first example. So it was news to me no matter long it's been around. Thanks Eric!

So that makes 4 ways to trap a key:
1. Inkey$
2. KeyHit
3. Keydown
4. Key

SmallBASIC had a way to associate a Key to a subroutine so that routine would  execute when the Key was pressed, maybe ON KEY for us?

Just looked it up: Yes! On Key(1) would trap the F1 key and send you to a GoSub or Sub you setup on same command. Numbers 1-10 dedicated to Function keys then 11-14? the arrow keys, this old stuff probably came with QB4.5?
This goes all the way back to GWBasic. When you start GWBasic you'll see a row of text at the bottom of the screen. Each word equates to an F key. This can be turned on and off using KEY ON/OFF. You as the programmer could also set these to whatever you liked as you have discovered.

That's why in many GWBasic programs the first line usually read:

KEY OFF: CLS

Here's a site with some info:

http://www.antonis.de/qbebooks/gwbasman/key.html
New to QB64pe? Visit the QB64 tutorial to get started.
QB64 Tutorial
Reply
#6
cool, thanks terry (my left shift key is worn out0 damn! Probably got some food stuck under it ;-))

I must of known this when I was using gw back in the late 80's early 90's. Must be the siren call of _KeyHit that made me forget Wink
b = b + ...
Reply
#7
Don't forget _DEVICES and INP, and PEEK/POKE methods, as well as various DECLARE LIBRARY code and $INCLUDE libraries...   

Wait...   Why is it any harder to read function keys than it is anything else, anyway?  It doesn't seem too limited to me.
Reply




Users browsing this thread: 1 Guest(s)