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
scanning the keyboard?
Re: scanning the keyboard?
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
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
Re: scanning the keyboard?
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
(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
-
- Super Gold Card
- Posts: 715
- Joined: Mon Nov 24, 2014 2:03 pm
Re: scanning the keyboard?
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?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
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;
}
Tobias
ʎɐqǝ ɯoɹɟ ǝq oʇ ƃuᴉoƃ ʇou sᴉ pɹɐoqʎǝʞ ʇxǝu ʎɯ 'ɹɐǝp ɥO