1. Reading ctrl-c's without crashing program
Hi, I need to make OidZone not drop to dos on a ctrl-C. I've been doing
get_keys() for the regular keyboard, And Jacques's keypad() thing for the
ctrl,alt,shift keys. ctrl-C kills get_key().
I tried using Jacques GetScanCode() but it doesn't work on 2 of my 3
machines. (both dx2-66's) works fine on my p166. His keytest.ex also
doesn't work on those machines, It correctly shows the shift ctrl and alt
keys, but not any other key, and I can't get out of it without
rebooting!
I looked at Dave Cuny's keys.e, but he's looking at the mouse and a bunch
of other stuff I don't need along with the keyboard, and it's way too slow
to check things I don't need. I need something lightning quick that will
read the scan codes or whatever that works on all machines. I can't have
even one extra if doing something I don't absolutely need.
I need something that gives me a number that doesn't change with the
shift,alt or ctrl, or crash on a crtl-c.
I need this yesterday, so if any of you can help, it would
be...um...helpful. Thanx.
Michael Packard
Lord Generic Productions
lgp at exo.com http://exo.com/~lgp
A Crash Course in Game Design and Production
http://exo.com/~lgp/euphoria
2. Reading ctrl-c's without crashing program
*** Reply to note of 02/11/97 15:17
here's the "short" version of my routine. you can cut this one down even
further, once you decide if you want the key code or the scan code:
-- CODE BEGINS HERE
-- direct read of the key buffer
constant
KEY_BUFFER = 1054, -- keyboard buffer; circular queue
FIRST_INDEX = 1050, -- index to first key in buffer
LAST_INDEX = 1052 -- index to last key in buffer
------------------------------------------------------------------
global function get_safe_key()
integer scan_code, key_code
-- get the key code and the alt key code
scan_code = peek( KEY_BUFFER + peek( FIRST_INDEX ) - 29 )
key_code = peek( KEY_BUFFER + peek( FIRST_INDEX ) - 30 )
-- clear the buffer
poke( FIRST_INDEX, peek( LAST_INDEX ) )
-- return the scan code
return scan_code
end function
-- CODE ENDS HERE
the main reason I embed a wait_key() in my version is it does a wait, allowing
other tasks on the machine a chance to step in - probably just as well left out
for your game.
hope this works!
-- david cuny
3. Reading ctrl-c's without crashing program
*** Reply to note of 02/11/97 16:42
Aaaargh! A chunk of code got *dropped* when i was pasting the function!
Apologies...
-- CODE BEGINS HERE ---
-- direct read of the key buffer
constant
KEY_BUFFER = 1054, -- keyboard buffer; circular queue
FIRST_INDEX = 1050, -- index to first key in buffer
LAST_INDEX = 1052 -- index to last key in buffer
----------------------------------------------------------------------------
global function get_safe_key()
integer scan_code, key_code
-- return key currently being pressed
-- return zero if no key is pressed
-- buffer is empty if indexes point to each other
if peek( FIRST_INDEX ) = peek( LAST_INDEX ) then
-- nothing in the buffer
return 0
end if
-- get the key code and the alt key code
scan_code = peek( KEY_BUFFER + peek( FIRST_INDEX ) - 29 )
key_code = peek( KEY_BUFFER + peek( FIRST_INDEX ) - 30 )
-- clear the buffer
poke( FIRST_INDEX, peek( LAST_INDEX ) )
-- return the scan code
return scan_code
end function
--- CODE ENDS HERE ---
-- david cuny
4. Re: Reading ctrl-c's without crashing program
Thanx, that did the trick. Boy, it's sure handy to have people around here
who know what I'm doing...
Michael Packard
Lord Generic Productions
lgp at exo.com http://exo.com/~lgp
A Crash Course in Game Design and Production
http://exo.com/~lgp/euphoria
5. Re: Reading ctrl-c's without crashing program
------=_NextPart_000_01BC18D0.D0531020
Content-Transfer-Encoding: 8bit
I needed a function to test if a key was pressed without disturbing the
buffer, here is:
-- By Jeszs Consuegra (jconsuegra at redestb.es)
include machine.e
include bitwise.e
constant FALSE = 0,
TRUE = 1,
ZeroFlag = #40
global function keypressed()
sequence reg_list
reg_list = repeat(0,10)
reg_list[REG_AX] = #0100
reg_list = dos_interrupt(#16, reg_list)
if AND(reg_list[REG_FLAGS], ZeroFlag) = ZeroFlag then
return FALSE
else
return TRUE
end if
end function
------------------
I still miss some SHR SHL bitwise shifts, and some serial port
procedures/functions to allow changing the baud rate, etc.
Any ideas?
Thanks
------=_NextPart_000_01BC18D0.D0531020
Content-Description: keypress.e ()