1. Scan codes...?

Could anyone tell me how to check the keyboard to see if a certain key is
pressed
down?

This way I could move my little guy in the up-left direction by pressing the
up key and the left key.

Does anyone have some library functions for this?

Thanks,
Bill

new topic     » topic index » view message » categorize

2. Re: Scan codes...?

re: Scan Codes

The arrow keys do not toggle flags like the shift keys. You read them like
any other key, using get_key(). The program KEY.EX is included with
Euphoria. Just type KEY at the command line, and press keys, and you will
see the scan key values.

If you want another example of how it can be done, you can take a look at
the file KEYS.E included in my editor, EE. It's got most of the key codes
defined as constants.

The KEYS.E file is probably more complex than you would want, because it
integrates the keys and mouse into the same routine. It also manually reads
the keys from the circular queue instead of using get_key(), so I can
safely read Ctrl-C without the program crashing. I think that the code is
made obsolete by allow_break() and check_break(), but I don't use it
because (1)allow_break() displays a ^C character, and (2) I've had trouble
getting it to work.

Here is a list of addresses you can check to see the status of the shift,
alt and control keys. I got it from the All Basic Code listings. &H17 is
the BASIC way of writing hex numbers; in Euphoria the number would be #17.

     &H17      -  Keyboard Flag
                  This Integer has 16 bits fields, as well, for the
KeyBoard

                  Byte 1:
                  &H80 - Insert On
                  &H40 - Caps Lock changed
                  &H20 - Num Lock changed
                  &H10 - Scroll Lock changed
                  &H08 - Alternate Shift pressed
                  &H04 - Control Shift key pressed
                  &H02 - Left Shift key pressed
                  &H01 - Right Shift key pressed

                  Byte 2;
                  &H80 - Insert Key is pressed
                  &H40 - Caps Lock Key is pressed
                  &H20 - Num Lock Key is pressed
                  &H10 - Scroll Lock key is pressed
                  &H08 - Suspend key has been toggled

Again, you can look at KEYS.E for an example of how this can be used.

Back to Lee's earlier question, I don't know if POKEing at &H17 will have
the effect of toggling the key state, but you certainly could try it.
KEYS.E also keeps track of the Insert/Delete key state, and changes the
cursor shape depending on which is selected.

Hope this helps.

-- David Cuny

new topic     » goto parent     » topic index » view message » categorize

3. Re: Scan codes...?

Well, nevermind everyone, looks like I found a keyboard interrupt handler in
the archive.  Shoulda checked first :)
Thanks tho...

new topic     » goto parent     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu