Qbasicnews.com

Full Version: Here's a little something...
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Suppose I am using a keyboard handler. When the keyboard handler is on, you can't use QB's INKEY$ function. The handler allows for swift keystroke detection, but what if you want to use both styles, one that constantly checks the status of a key press using the handler, and one like INKEY$, where you want a routine to execute once the key is released after pressing it. Here's a routine you can use to do thatSadIt uses RELKEY from rellib, but that can be changed to any sort of kb handler. SKey stands for SlowKey)

Code:
SUB SKey (Flag%, KeyCode%, ScanCode%)

  Flag% = 0

  IF KeyCode% = -1 AND RelKey(ScanCode%) = 0 THEN KeyCode% = 0
  
  IF RelKey(ScanCode%) AND KeyCode% = 0 THEN
    KeyCode% = -1
    Flag% = -1
  END IF

END SUB

...where Flag% is a variable that is passed back to you givingyou the status, KeyCode% is a flag variable used if you have more than one key you want this sub to work on(an ID variable for the key), and Scancode% is the scancode of the key.
All you need is a flag variable for the key you want. If you want many different keys, set up a TYPE, like so:

Code:
TYPE SlowKeysType
  EnterKey as integer
  EscKey as integer
  SPaceKey as integer
END TYPE

DIM SHARED SlowKeys AS SlowKeysType

Here's how you would use the subroutine:

Code:
SKey Flag%, SlowKey.CtrlKey, &H1D
    IF Flag% = -1 THEN Execute Code

So this routine allows the keyboard handler to be on, and still have the ability to execute code with full keypresses. I thought I might share this with you. :wink:
Huh? When i use a keyboard handler i can also use INKEY$...
hmmm, it never works for me, weird. I'm using Rellib's, which one are you using? Anyways, this routine is still good if you want to make it execute the routine only after the user releases, since INKEY$ works a bit differently.
Quote:Huh? When i use a keyboard handler i can also use INKEY$...

Ows?
Quote:
dark_prevail Wrote:Huh? When i use a keyboard handler i can also use INKEY$...

Ows?

Ows? Did something hurt? If you are asking about how i can use inkey$ and a KBH on my comp, i have no idea. Although I havent ever tried Rellib, so maybe its just it doesnt work using it. Not that I dont like Rellib... I think its awesome ;D I just cant do any debugging because it regularly hangs my computer if I program with it. =(
Ows again?

Code Pls....
If the keyboard handler passes control back to the original handler, then INKEY$ will work. If it doesn't (like DirectQB's) than INKEY$ won't work.