From: rvs@parst1.UUCP (Roelof van Suilichem)
Newsgroups: comp.os.msdos.programmer
Subject: Re: Reading ALT keys with bioskey in TC++?
Date: 3 Sep 92 17:19:44 GMT
Organization: Paradigm Systems Technology

In article <1992Aug25.184207.7825@lclark.edu> harrison@sun.lclark.edu (Mark Harrison) writes:

>Hi.  I am reading ALT+<key> from the keyboard with bioskey (in TC++ 3.0.)
>But that gives me values that map to the physical layout of the keyboard. 
>Is there an easy way to translate this value into one that will tell me
>the Ascii code of the key?  For instance, how do I transform 0x3100
>(ALT+N) to get the ascii code of N?  Will I need to write a function that
>will do this for all the ALT values I want to check for?  If so, then no
>problem.  I just don't want to reinvent any wheels.

OK, here is my invented wheel.  Might save you some typing.
Use as you want, at your own risk.  If you are going to use it
just Email me so I get some satisfaction of knowing that somebody
is actually using it.

Search for the scissors ("8<") to fund the cutoff points for the files.


---8<------------------------------KBD.H-------------------------------
#ifndef KBD_H
#define KBD_H
#define KEY  0
#define CTRL 1
#define ALT  2
#define EscKey        27
#define BsKey          8
#define CrKey         13
#define CtrlCrKey     10
#define TabKey         9
#define ShiftTabKey  271
#define LeftKey      331
#define RightKey     333
#define DownKey      336
#define UpKey        328
#define HomeKey      327
#define EndKey       335
#define PgupKey      329
#define PgdnKey      337
#define InsKey       338
#define DelKey       339
#define CtrlLeftKey  371
#define CtrlRightKey 372
#define CtrlHomeKey  375
#define CtrlEndKey   373
#define CtrlPgupKey  388
#define CtrlPgdnKey  374
#define F1Key        315
#define F2Key        316
#define F3Key        317
#define F4Key        318
#define F5Key        319
#define F6Key        320
#define F7Key        321
#define F8Key        322
#define F9Key        323
#define F10Key       324
#define ShiftF1Key   340
#define ShiftF2Key   341
#define ShiftF3Key   342
#define ShiftF4Key   343
#define ShiftF5Key   344
#define ShiftF6Key   345
#define ShiftF7Key   346
#define ShiftF8Key   347
#define ShiftF9Key   348
#define ShiftF10Key  349
#define CtrlF1Key    350
#define CtrlF2Key    351
#define CtrlF3Key    352
#define CtrlF4Key    353
#define CtrlF5Key    354
#define CtrlF6Key    355
#define CtrlF7Key    356
#define CtrlF8Key    357
#define CtrlF9Key    358
#define CtrlF10Key   359
#define AltF1Key     360
#define AltF2Key     361
#define AltF3Key     362
#define AltF4Key     363
#define AltF5Key     364
#define AltF6Key     365
#define AltF7Key     366
#define AltF8Key     367
#define AltF9Key     368
#define AltF10Key    369
#define CtrlAKey       1
#define CtrlBKey       2
#define CtrlCKey       3
#define CtrlDKey       4
#define CtrlEKey       5
#define CtrlFKey       6
#define CtrlGKey       7
#define CtrlHKey       8
#define CtrlIKey       9
#define CtrlJKey      10
#define CtrlKKey      11
#define CtrlLKey      12
#define CtrlMKey      13
#define CtrlNKey      14
#define CtrlOKey      15
#define CtrlPKey      16
#define CtrlQKey      17
#define CtrlRKey      18
#define CtrlSKey      19
#define CtrlTKey      20
#define CtrlUKey      21
#define CtrlVKey      22
#define CtrlWKey      23
#define CtrlXKey      24
#define CtrlYKey      25
#define CtrlZKey      26
#define AltQKey      272
#define AltWKey      273
#define AltEKey      274
#define AltRKey      275
#define AltTKey      276
#define AltYKey      277
#define AltUKey      278
#define AltIKey      279
#define AltOKey      280
#define AltPKey      281
#define AltAKey      286
#define AltSKey      287
#define AltDKey      288
#define AltFKey      289
#define AltGKey      290
#define AltHKey      291
#define AltJKey      292
#define AltKKey      293
#define AltLKey      294
#define AltZKey      300
#define AltXKey      301
#define AltCKey      302
#define AltVKey      303
#define AltBKey      304
#define AltNKey      305
#define AltMKey      306
Public int kbdPressed (void);
Public int kbdGet (void);
Public int kbdTx (int key, int from, int to);
#endif
---------8<------KBD.C--------------------------------------------
#include <bios.h>
#include <conio.h>
#include <dos.h>
#include "mydefs.h"  /* #define Public and Private; compiler flags, etc */
#include "kbd.h"
Private int chartable [][3] =
    {
    {'Q',CtrlQKey,AltQKey},
    {'W', CtrlWKey, AltWKey},
    {'E', CtrlEKey, AltEKey},
    {'R', CtrlRKey, AltRKey},
    {'T', CtrlTKey, AltTKey},
    {'Y', CtrlYKey, AltYKey},
    {'U', CtrlUKey, AltUKey},
    {'I', CtrlIKey, AltIKey},
    {'O', CtrlOKey, AltOKey},
    {'P', CtrlPKey, AltPKey},
    {'A', CtrlAKey, AltAKey},
    {'S', CtrlSKey, AltSKey},
    {'D', CtrlDKey, AltDKey},
    {'F', CtrlFKey, AltFKey},
    {'G', CtrlGKey, AltGKey},
    {'H', CtrlHKey, AltHKey},
    {'J', CtrlJKey, AltJKey},
    {'K', CtrlKKey, AltKKey},
    {'L', CtrlLKey, AltLKey},
    {'Z', CtrlZKey, AltZKey},
    {'X', CtrlXKey, AltXKey},
    {'C', CtrlCKey, AltCKey},
    {'V', CtrlVKey, AltVKey},
    {'B', CtrlBKey, AltBKey},
    {'N', CtrlNKey, AltNKey},
    {'M', CtrlMKey, AltMKey}
    };
Public int kbdPressed (void)
    {
    return bioskey(1);
    }
Public int kbdGet (void)
    {
    int c;
    c = (int) getch();
    if (!c)
        {
        c = getch();
        c += 256;
        }
    return c;
    }
Public int kbdTx (int key, int from, int to)
    {
    unsigned char i;
    if (from<KEY || from>ALT || to<KEY || to>ALT)
        return -1;
    for (i=0;i<26;i++)
        if (chartable[i][from]==key)
            return chartable[i][to];
    return -1;
    }
---8<----------------------------------------------------------

Hope this helps.

/*------------------------------------------------*\
| Roelof J. van Suilichem | Email: rvs@parst1.uucp |
|-------------------------| Snail: P. O. Box 75026 |
|                         |        Lynnwood Ridge  |
|                         |        0040            |
|                         |        South Africa    |
\*------------------------------------------------*/
Newsgroups: comp.os.msdos.programmer