April 25, 2024, 04:04:40 AM

News:

Own IWBasic 2.x ? -----> Get your free upgrade to 3.x now.........


KEYDOWN keyword

Started by arono, April 29, 2017, 02:10:34 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

arono

Hi,

Well I thought this was going to be straightforward, but I'm missing something regarding KEYDOWN.

I want to determine in the fastest time possible if the '5' key is pressed on the keypad portion of the keyboard.  Using code in the IDKEYDOWN section of my 'mainw' subroutine, I can detect any of the keypad keys except the '5' key.

So I tried using KEYDOWN outside of 'mainw' with code like this:
   CONST DIK_NUMPAD5 = 0x4C

    IF KEYDOWN(DIK_NUMPAD5)  THEN . . . . .

For whatever reason, this doesn't work.  I tried it with the NUMLOCK key down and up with no luck  I also tried other keypad keys and the regular keyboard keys with their own directinput constants but this command is never returning TRUE.

What am I missing??

Thanks again folks.


billhsln

April 29, 2017, 09:08:45 PM #1 Last Edit: April 29, 2017, 09:27:40 PM by billhsln
You might want to add this and see what the results look like:

SELECT @MESSAGE
  case @IDCHAR
MOVE win,4,210
print win,"Ascii code = ",@CODE,"   "
  case @IDKEYDOWN
MOVE win,4,240
print win,"virtual code = ",@CODE,"   "


Under @IDKEYDOWN, @CODE returns a 12 for keypad 5 (at least for me).

It will at least show you the values received from the system and it might help track down what you are looking for.

Bill
When all else fails, get a bigger hammer.

Egil

April 30, 2017, 04:27:37 AM #2 Last Edit: April 30, 2017, 04:31:05 AM by Egil
If you want the program to react on on a specific key and ignore all the others, you can use GETKEYSTATE:


case @IDKEYDOWN
if GETKEYSTATE(0x1B) then run=0         ' ESC is pressed
if GETKEYSTATE(0x21) then fq=fq+10 ' PG UP pressed
if GETKEYSTATE(0x22) then fq=fq-10 ' PG DOWN pressed
if GETKEYSTATE(0x26) then fq=fq+1 ' UP ARROW pressed


The expressions are true only if the particular keys are pressed.
Hexadecimal codes are found in the appendix to the Users Guide, under "Virtual key codes".


Good luck!

Egil
Support Amateur Radio  -  Have a ham  for dinner!