scanning the keyboard?

Anything QL Software or Programming Related.
tschak909
ROM Dongle
Posts: 14
Joined: Sat Jul 06, 2019 5:00 am

scanning the keyboard?

Postby tschak909 » Thu Jul 11, 2019 10:50 pm

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


User avatar
tofro
QL Wafer Drive
Posts: 1606
Joined: Sun Feb 13, 2011 10:53 pm
Location: SW Germany

Re: scanning the keyboard?

Postby tofro » Thu Jul 11, 2019 11:42 pm

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


ʎɐqǝ ɯoɹɟ ǝq oʇ ƃuᴉoƃ ʇou sᴉ pɹɐoqʎǝʞ ʇxǝu ʎɯ 'ɹɐǝp ɥO
tschak909
ROM Dongle
Posts: 14
Joined: Sat Jul 06, 2019 5:00 am

Re: scanning the keyboard?

Postby tschak909 » Fri Jul 12, 2019 12:15 am

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


stevepoole
Trump Card
Posts: 202
Joined: Mon Nov 24, 2014 2:03 pm

Re: scanning the keyboard?

Postby stevepoole » Fri Jul 12, 2019 5:53 am

Hi Thom,

What sort of keyboard are you using ?

Steve Poole.


User avatar
tofro
QL Wafer Drive
Posts: 1606
Joined: Sun Feb 13, 2011 10:53 pm
Location: SW Germany

Re: scanning the keyboard?

Postby tofro » Fri Jul 12, 2019 7:22 am

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


ʎɐqǝ ɯoɹɟ ǝq oʇ ƃuᴉoƃ ʇou sᴉ pɹɐoqʎǝʞ ʇxǝu ʎɯ 'ɹɐǝp ɥO

Who is online

Users browsing this forum: No registered users and 5 guests