Mail Archives: djgpp/1997/07/30/18:30:25
This is a multi-part message in MIME format.
--------------186F4AFD1958
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
Jan Hubicka wrote:
>
> Hi. I need to know ascii codes of pressed keys. But I also need to be
> informed about ther release. Whats the easiest way to do this?
>
> Honza
>
> ------------------------------------------------------------------------------
> Have you browsed my www pages? Look at:
> http://www.paru.cas.cz/~hubicka
> Koules-the game for Svgalib,X11 and OS/2, Xonix-the game for X11
> czech documentation for linux index, original 2D computer art and
> funny 100 years old photos and articles are there!
Attached is my keyboard.h keypress handler. The code is not documented
well, but is pretty simple. Basically, you call install_keyboard() at
the beginning and remove_keyboard() at the end. To check for a
keypress, just use an if statement, like this:
if (key[KEY_ENTER])
{
call functions here.
};
BTW, key is an array that is indexed by any one of the defined key
codes, so key[<key define>] is 1 if the key is down, and 0 if it is not
pressed.
Hope this helps.
--
-Begin Signature-
Isaac Waldron <waldroni AT lr DOT net> N1YZI
http://www.geocities.com/SiliconValley/Lakes/5703/home.html
-End Signature-
--------------186F4AFD1958
Content-Type: text/plain; charset=us-ascii; name="Keyboard.h"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline; filename="Keyboard.h"
/*
keyboard.h
A C++ header with functions that override the BIOS keayboard handler
Author: Isaac Waldron
*/
#include <dos.h>
#include <dpmi.h>
#include <go32.h>
#define KEYBOARD_INT 0x09
#define KEY_BUFFER 0x60
#define KEY_CONTROL 0x61
#define INT_CONTROL 0x20
#define KEY_ESC 1 /* keyboard scan codes */
#define KEY_1 2
#define KEY_2 3
#define KEY_3 4
#define KEY_4 5
#define KEY_5 6
#define KEY_6 7
#define KEY_7 8
#define KEY_8 9
#define KEY_9 10
#define KEY_0 11
#define KEY_MINUS 12
#define KEY_EQUALS 13
#define KEY_BACKSPACE 14
#define KEY_TAB 15
#define KEY_Q 16
#define KEY_W 17
#define KEY_E 18
#define KEY_R 19
#define KEY_T 20
#define KEY_Y 21
#define KEY_U 22
#define KEY_I 23
#define KEY_O 24
#define KEY_P 25
#define KEY_OPENBRACE 26
#define KEY_CLOSEBRACE 27
#define KEY_ENTER 28
#define KEY_CTRL 29
#define KEY_A 30
#define KEY_S 31
#define KEY_D 32
#define KEY_F 33
#define KEY_G 34
#define KEY_H 35
#define KEY_J 36
#define KEY_K 37
#define KEY_L 38
#define KEY_COLON 39
#define KEY_QUOTE 40
#define KEY_TILDE 41
#define KEY_LSHIFT 42
#define KEY_Z 44
#define KEY_X 45
#define KEY_C 46
#define KEY_V 47
#define KEY_B 48
#define KEY_N 49
#define KEY_M 50
#define KEY_COMMA 51
#define KEY_STOP 52
#define KEY_SLASH 53
#define KEY_RSHIFT 54
#define KEY_ASTERISK 55
#define KEY_ALT 56
#define KEY_SPACE 57
#define KEY_CAPSLOCK 58
#define KEY_F1 59
#define KEY_F2 60
#define KEY_F3 61
#define KEY_F4 62
#define KEY_F5 63
#define KEY_F6 64
#define KEY_F7 65
#define KEY_F8 66
#define KEY_F9 67
#define KEY_F10 68
#define KEY_NUMLOCK 69
#define KEY_SCRLOCK 70
#define KEY_HOME 71
#define KEY_UP 72
#define KEY_PGUP 73
#define KEY_MINUS_PAD 74
#define KEY_LEFT 75
#define KEY_5_PAD 76
#define KEY_RIGHT 77
#define KEY_PLUS_PAD 78
#define KEY_END 79
#define KEY_DOWN 80
#define KEY_PGDN 81
#define KEY_INSERT 82
#define KEY_DEL 83
#define KEY_F11 87
#define KEY_F12 88
#define BREAK 128 //Key "no-longer pressed" code
unsigned char key[128];
_go32_dpmi_seginfo Old_KeyBoard;
_go32_dpmi_seginfo sinfo;
void key_handler(void)
{
unsigned char temp, keyCode;
keyCode = inp(KEY_BUFFER);
temp = inp(KEY_CONTROL);
temp = temp | 0x82;
outp(KEY_CONTROL, temp);
temp = temp & 0x7f;
outp(KEY_CONTROL, temp);
outp(INT_CONTROL, 0x20);
if (keyCode > 128)
{
key[keyCode - 128] = 0;
}
else
{
key[keyCode] = 1;
};
};
void key_handler_lock()
{
};
int install_keyboard(void)
{
int i;
for (i = 0; i < 127; i++)
{
key[i] = 0;
};
_go32_dpmi_lock_data(&key, sizeof(key));
_go32_dpmi_lock_code(key_handler, (unsigned long)(key_handler_lock - key_handler));
_go32_dpmi_get_protected_mode_interrupt_vector(KEYBOARD_INT, &Old_KeyBoard);
sinfo.pm_offset = (long unsigned)&key_handler;
sinfo.pm_selector = (short unsigned)_my_cs;
_go32_dpmi_allocate_iret_wrapper(&sinfo);
_go32_dpmi_set_protected_mode_interrupt_vector(KEYBOARD_INT, &sinfo);
};
void remove_keyboard(void)
{
_go32_dpmi_set_protected_mode_interrupt_vector(KEYBOARD_INT, &Old_KeyBoard);
_go32_dpmi_free_iret_wrapper(&sinfo);
};
--------------186F4AFD1958--
- Raw text -