Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Keyboard input - multiple keys?
#11
Okay, i figured out the problem.

See, INP returns a number below 128 when a key is pressed, and it returns a value that's corresponds with (the key press + 128) when that key is unpressed.

Arrow keys are an exception though; When you press them, they return a unique value, but when you un-press them, all four return the same value of 170 - which does not correspond with the keypress. I needed to add this fixer for that:

Code:
FUNCTION Multikey (keynum)

KeyInp = INP(96)
IF KeyInp <= 127 THEN
KeyInput(KeyInp) = 1
END IF
IF KeyInp >= 128 THEN
KeyInput(KeyInp - 128) = 0
IF KeyInp = 170 THEN           ' Arrowkeys are an exception
KeyInput(75) = 0
KeyInput(77) = 0
END IF
END IF

Multikey = KeyInput(keynum)

END FUNCTION

Of course, if I needed to have the user press the left and right arrow keys (75 and 77) at the same time, then I guess I'd have some problems. Fortunately I don't need that.

Sorry if I didn't really explain this very well, but I guess it's irrelevant because nobody else had my problem :bounce:

Thanks to everyone who helped me out!
img]http://b.domaindlx.com/cygh/mycophob3.gif[/img]
Reply
#12
Well I can guess what your problem is: You are using the arrow keys without Num lock On. In this case the arrow keys do not return a standard release code. You must activate Num Lock before using INP(96) to read arrow keys.
Code:
DEF SEG = &H40: POKE &H17, PEEK(&H17) AND NOT 32

What's so bad about mushrooms? Big Grin
Antoni
Reply
#13
Antoni wrote
Quote:DEF SEG = &H40: POKE &H17, PEEK(&H17) AND NOT 32
Isn't NOT 32 just 0, which would make PEEK(&H17) AND NOT 32 also 0. Am I misunderstanding this? Also if this switches Num Lock on, how do you switch it off?
hrist Jesus came into the world to save sinners, of whom I am first.(I Timothy 1:15)

For God so loved the world, that He gave His only begotten Son,
that whoever believes in Him should not perish, but have eternal life.(John 3:16)
Reply
#14
32 = 0000000000100000, so NOT 32 = 1111111111011111 which is not 0 Smile
SCUMM (the band) on Myspace!
ComputerEmuzone Games Studio
underBASIC, homegrown musicians
[img]http://www.ojodepez-fanzine.net/almacen/yoghourtslover.png[/i
Reply
#15
I should have known that. Now I do. About My other question, If
Code:
DEF SEG = &H40: POKE &H17, PEEK(&H17) AND NOT 32
makes sure Num Lock is on, would
Code:
DEF SEG = &H40: POKE &H17, PEEK(&H17) OR 32
make sure it is off?
hrist Jesus came into the world to save sinners, of whom I am first.(I Timothy 1:15)

For God so loved the world, that He gave His only begotten Son,
that whoever believes in Him should not perish, but have eternal life.(John 3:16)
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)