Page 1 of 1

scanning the keyboard?

Posted: Thu Jul 11, 2019 10:50 pm
by tschak909
I'm noticing that the keys that I get back are ASCII encoded. This is good, except for when I need to do certain key combinations that conflict with standard ASCII conventions,
an example of this is CTRL-H, which is nominally mapped to back-space.

On other platforms, to deal with this, I use the ASCII key mapping most of the time, and only do small exceptions to handle the conflicting keys, to consume them before the rest of my code gets to it.

Is there a way I can scan for specific keys? namely:

CTRL-H
CTRL-M
etc?

-Thom

Re: scanning the keyboard?

Posted: Thu Jul 11, 2019 11:42 pm
by tofro
Basically all of the keys on the QL's keyboard will produce a specific ASCII code, except <CTRL>-C and <CTRL>-F5 (these are intercepted by the system and cannot be caught by any means).

The Shift, ALT and CAPS key will not produce a code on their own.

(See the QL Manual here on "Character set and keys".

Any combination of <ALT> + some key combination produces a character with the value of 255 plus the key combination (so actually 2 characters).

So, if you're not interested in modifier keys alone, you're fine with reading the keyboard in ASCII through, for example, io_fbyte (). In case you want to be able to see modifier keys alone, look into mt_ipcom () to read the raw keycodes. This is, however, a bit more tricky, as you need to scan the matrix yourselves by directly talking to the keyboard co-processor.

If you're asking for a key with io_fbyte(), you will get it without interpretation from the system, even a backspace or cursor key. No need to revert to special methods, exept for modifier keys alone.

Tobias

Re: scanning the keyboard?

Posted: Fri Jul 12, 2019 12:15 am
by tschak909
Oddly enough, I only get some keys back with io_fbyte (The window is a con), keys like backspace seem to emit 0xfff

(but I was able to get them with getchar(), but this adds a whole chunk of posix compatibility that I do not want, bigger bin for no good reason.)

-Thom

Re: scanning the keyboard?

Posted: Fri Jul 12, 2019 5:53 am
by stevepoole
Hi Thom,

What sort of keyboard are you using ?

Steve Poole.

Re: scanning the keyboard?

Posted: Fri Jul 12, 2019 7:22 am
by tofro
tschak909 wrote:Oddly enough, I only get some keys back with io_fbyte (The window is a con), keys like backspace seem to emit 0xfff
io_fbyte() should never return 0xff unless ALT is pressed together with another key combination. This looks more like you interpret an error code as character, maybe?

Code: Select all

#include <qdos_h>
#include <stdio_h>

int main (void){
  int chid = fgetchid (stdin);

  int rets;
  unsigned char keyChar;

  while (1) {
    rets = io_fbyte (chid, 0,  &keyChar);
    if (rets < 0)
      continue;
    printf ("Pressed: %c Code: ; %d\n", keyChar, keyChar);
    if (keyChar == 27)
      return;
  }
This should give 192 for <cursor left> and 194 for <backspace> (which is in fact <CTRL><Cursor left>). At least it does here.

Tobias