[comp.sys.atari.st] Control-F1, Alt-F1 ???

ger@qtecmuc.UUCP (06/17/87)

Hello there,

does anyone know, if there is a way to distinguish between
Functionkey F1, ALT-F1 and CTRL-F1 using C (MWC).
All routines like Bconin or Crawcin don't make a difference at all.
I need this to port an application from MS-DOS, where I can get all
the combinations.
The keys are there on the keyboard, so why shouldn't I be able
to read them correctly.
Any hints, sources, .o's and the like are welcome !
Thank you all
   
   Gerhard Pehland
   Quantec Tonstudiotechnik GmbH
   Munich W-Germany
   UUCP:  ....!seismo!unido!qtecmuc!ger

sansom@trwrb.UUCP (Richard Sansom) (06/22/87)

In article <19400005@qtecmuc.UUCP> ger@qtecmuc.UUCP writes:
>does anyone know, if there is a way to distinguish between
>Functionkey F1, ALT-F1 and CTRL-F1 using C (MWC).
>All routines like Bconin or Crawcin don't make a difference at all.

Try this (I hope I haven't made any glaringly obvious errors - this is all
from memory):

--- cut here ---
/*
 * This little program will display the key scan codes and the ASCII
 * character codes of the keys typed in at the keyboard.  Exit by typing "Q".
 */

#include <stdio.h>
#include <osbind.h>

#define CON 2

main() {
    long lc;
    char scan, ascii;

    for (;;) {
	if (Bconstat(CON)) {
	    lc = Bconin(CON);
	    ascii = (char)(lc & 0xffL);
	    scan = (char)((lc >> 16) & 0xffL);
	    printf("scan = 0x%02x, ascii = 0x%02x\n", scan, ascii);
	    if (ascii == 'Q')
		exit(0);
	}
    }
}
-- 
   /////////////////////////////////////\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
  /// Richard E. Sansom                   TRW Electronics & Defense Sector \\\
  \\\ {decvax,ucbvax,ihnp4}!trwrb!sansom  Redondo Beach, CA                ///
   \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\/////////////////////////////////////

braner@batcomputer.tn.cornell.edu (braner) (06/22/87)

[]

Remember that the BIOS calls return a long word, with the ASCII code
in the lower 8 bits and the scan-code (tied to the physical key) in
the upper word's lower byte (bits 16-23).  The Fn keys return an ASCII
code of zero, and so do Alt-keys.

There is a separate BIOS function that returns the current status of
the various shift keys (incl. Alt, Ctrl and Capslock).  You need to
call it right after you get a keypress to get the right info.  Note
that the shift keys change the ASCII code returned by some keys (e.g.
shift-letter) but not the scan-code.  Except that shifted Fn keys have
different scan codes than the same Fn keys unshifted, and so do Alt-<x>,
where <x> is a key in the set {[1],...,[=]} (row above QWERTY).

- Moshe Braner

apratt@atari.UUCP (Allan Pratt) (06/25/87)

in article <19400005@qtecmuc.UUCP>, ger@qtecmuc.UUCP says:
> does anyone know, if there is a way to distinguish between
> Functionkey F1, ALT-F1 and CTRL-F1 using C (MWC).
> All routines like Bconin or Crawcin don't make a difference at all.

What you need to remember is that the BIOS and GEMDOS calls return
a LONG value.  The highest byte of this value can contain the shift-key
state when the key was hit.  You tell the OS to put the shift key state
in that byte by setting bit 3 in the (published) system variable "conterm"
to 1 (that is, *(char *)0x484 |= 4;).  Better clear it again before
your program exits, though, because the desktop might not be able to
handle it (use *(char *)0x484 &= ~4;).

The upper byte is bit-mapped as follows (0 means up, 1 means down):

Bit	Key
0	Right shift
1	Left shift
2	Ctrl
3	ALT
4	Caps-lock (toggles with each press of the key)
5	Right mouse button
6	Left mouse button
7	Reserved, currently zero

/----------------------------------------------\
| Opinions expressed above do not necessarily  |  -- Allan Pratt, Atari Corp.
| reflect those of Atari Corp. or anyone else. |     ...lll-lcc!atari!apratt
\----------------------------------------------/	(APRATT on GEnie)

manis@ubc-cs.UUCP (Vincent Manis) (06/27/87)

In article <766@atari.UUCP> apratt@atari.UUCP (Allan Pratt) writes:

>> does anyone know, if there is a way to distinguish between
>> Functionkey F1, ALT-F1 and CTRL-F1 using C (MWC).
>...You tell the OS to put the shift key state
>in that byte by setting bit 3 in the (published) system variable "conterm"
>to 1 (that is, *(char *)0x484 |= 4;).  Better clear it again before
>your program exits, though, because the desktop might not be able to
>handle it (use *(char *)0x484 &= ~4;).

One slight point: "conterm" is in protected memory. You will get cherry
bombs if you do what Allan says without turning off protect. In MWC, the
way to do it is to use the peek and poke [sic!] functions.

\begin{flame}
This one is directed at IBM, not Atari, who merely copied IBM slavishly. 
I tried to write a routine which would let me read keystrokes in which the
ALT key sets the high bit of the code (thus letting you turn on extended 
graphics). What you do is to use only the scan code and shift bits, ignoring
the translated character; depending on the state of the shift bits, you use
one of three translation tables. It all worked nicely...until I tried 
ALT+digit. The codes in the tables are wrong. At first I thought it was yet
another BIOS bug, until I happened to notice in an IBM Tech Ref Manual the
same rules. Ugh.
\end{flame}

-----
Vincent Manis                {seismo,uw-beaver}!ubc-vision!ubc-cs!manis
Dept. of Computer Science    manis@cs.ubc.cdn
Univ. of British Columbia    manis%ubc.csnet@csnet-relay.arpa  
Vancouver, B.C. V6T 1W5      manis@ubc.csnet
(604) 228-6770 or 228-3061

"To lose one parent, Mr Worthing, may be regarded as a misfortune; but
to lose both looks like carelessness." -- Oscar Wilde

ger@qtecmuc.UUCP (06/29/87)

	in article <19400005@qtecmuc.UUCP>, ger@qtecmuc.UUCP says:
	> does anyone know, if there is a way to distinguish between
	> Functionkey F1, ALT-F1 and CTRL-F1 using C (MWC).
	> All routines like Bconin or Crawcin don't make a difference at all.
	...
	state when the key was hit.  You tell the OS to put the shift
	key state in that byte by setting bit 3 in the (published)
	system variable "conterm" to 1 (that is, *(char *)0x484 |=
	4;).  Better clear it again before your program exits, though,
	because the desktop might not be able to handle it (use *(char
	*)0x484 &= ~4;).

Thank you, it (almost) works fine !!!
But it should be '|= 8' and '&= ~8' in your examples.
                     ^           ^

Gerhard Pehland
UUCP:  ...!seismo!unido!qtecmuc!ger

apratt@atari.UUCP (Allan Pratt) (06/29/87)

in article <1503@ubc-cs.UUCP>, manis@ubc-cs.UUCP (Vincent Manis) says:
> 
> In article <766@atari.UUCP> apratt@atari.UUCP (Allan Pratt) writes:
> 
>>> does anyone know, if there is a way to distinguish between
>>> Functionkey F1, ALT-F1 and CTRL-F1 using C (MWC).
>>...You tell the OS to put the shift key state
>>in that byte by setting bit 3 in the (published) system variable "conterm"
>>to 1 (that is, *(char *)0x484 |= 4;).  Better clear it again before
>>your program exits, though, because the desktop might not be able to
>>handle it (use *(char *)0x484 &= ~4;).
> 
> One slight point: "conterm" is in protected memory. You will get cherry
> bombs if you do what Allan says without turning off protect. In MWC, the
> way to do it is to use the peek and poke [sic!] functions.
> 

Alas... I tried to edit this message before it went out..  The correct
value for the |= and &= is 8 (and ~8), not 4 (and ~4).  What Vincent
refers to as "turning off protect" is really entering Supervisor mode
on the 68K.  The following funtions do what you want:

#include <osbind.h>		/* get OS binding for Super() */

setbit()	/* sets bit 3 of conterm, so shift state is in upper byte */
{
	long oldssp = Super(0L);
	*(char *)0x484 |= 8;
	Super(oldssp);
}

clrbit()	/* clears bit 3 of conterm, so desktop doesn't gag */
{
	long oldssp = Super(0L);
	*(char *)0x484 &= ~8;
	Super(oldssp);
}

You have to link with osbind.o for this to work.

Between the Super(0L) call and the Super(oldssp) call, you are in
Supervisor mode.  YOU CAN'T DO OS CALLS HERE.  If you need to do
OS calls, use Supexec() instead.

/----------------------------------------------\
| Opinions expressed above do not necessarily  |  -- Allan Pratt, Atari Corp.
| reflect those of Atari Corp. or anyone else. |     ...lll-lcc!atari!apratt
\----------------------------------------------/	(APRATT on GEnie)

ger@qtecmuc.UUCP (07/06/87)

Another way to get into protected memory is the use of the Super() function.
Goes sumpn like this:

long savestack;

savestack=Super(0L);
fiddle_around_with_protected_memory();
Super(savestack);

Gerhard Pehland
UUCP: ...!seismo!unido!qtecmuc!ger