Do any of you know how to write a Turbo C function that accepts a key code as a parameter and returns true or false according to whether it is held down? For example "Func(65)" would return true if the "A" key was down and false if any other key or no key was held down. kbhit and getch are just too slow.
Turbo C Help
Started by
AlephMobius
, Mar 29 2003 07:56 PM
6 replies to this topic
#1
Posted 29 March 2003 - 07:56 PM
#2
Posted 29 March 2003 - 11:52 PM
You can replace the function kbhit() by the code below, this is MUSCH faster:
Then for your function, I'have done this "getkey like" function a long time ago:
To know the return value of a key you have to use TOUCHE. For example for the key 'A' this function should return 0x1E400040
This function return 0 if no key is pressed.
The other way is to use multikeypress but it's more difficult to implement...
peekb(0x41, 0xD))==(peekb(0x41, 0xB)
Then for your function, I'have done this "getkey like" function a long time ago:
#include <dos.h> unsigned long getkey (void) { return (peek(0, 0x4ac) + (((unsigned long)(peek(0, 0x4ae)) << 16))) * CASIO; }
To know the return value of a key you have to use TOUCHE. For example for the key 'A' this function should return 0x1E400040
This function return 0 if no key is pressed.
The other way is to use multikeypress but it's more difficult to implement...
#3
Posted 30 March 2003 - 08:39 AM
2072, you really like complicate things... and what's the length of the value returned ?? long type (32bits if I remember good)
Here is a good key function:
and key is an integer ... 16bits only!!
Do a little program to know the value of a key, it isn't very complicated!
and that's all ...
Here is a good key function:
key=peekb(0x40,0xAF);
and key is an integer ... 16bits only!!
Do a little program to know the value of a key, it isn't very complicated!
and that's all ...
#4
Posted 30 March 2003 - 09:48 AM
multiple key powaaaa
#5
Posted 30 March 2003 - 11:23 PM
How would it change if you did it on the PC?
#6
Posted 30 March 2003 - 11:54 PM
First of all, in windows, you'de be working in protected mode, so you can't access those parts of memory
Secondly, the keyboard buffer isn't held in the same area of memory on the pc
so, reading keys directly from memory would be different
(under DOS you might do it, but from which address, I don't know)
Secondly, the keyboard buffer isn't held in the same area of memory on the pc
so, reading keys directly from memory would be different
(under DOS you might do it, but from which address, I don't know)
#7
Posted 31 March 2003 - 09:13 PM
peekb returns a char type so it's 8 bits long, key should be a char.key=peekb(0x40,0xAF);
and key is an integer ... 16bits only!!
Do a little program to know the value of a key, it isn't very complicated!
and that's all ...
You don't have to make a litle program, you can use TOUCHE to know this value in the "1: Touche" menu entry (like for my function): The values of offsets 0x4a:0xc, 0x4a:0xd, 0x4a:0xe, 0x4a:0xf are displayed...
0 user(s) are reading this topic
0 members, 0 guests, 0 anonymous users