Re: Insert Keycode into Keyboard Buffer?
- Posted by "Juergen Luethje" <j.lue at gmx.de> Jun 01, 2004
- 556 views
Bob wrote: [snipped old text] > This works for DOS32: > > }}} <eucode> > > constant -- these are from keys.e by David Cuny from Euphoria Editor (EE) > 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 integer KEY_CODE, SCAN_CODE -- these are written by the reading > routine in keys.e > > ----------------------------- > -- stuff a key into the keyboard buffer > > -- This is for procedures which do their own keyboard polling instead of > -- mainloop(). This enables procedures called from mainloop() to pass on > -- keys like mode keys to mainloop() after returning. Be careful not to > -- stuff a key which would result in an endless loop. > global procedure put_key(integer keycode, integer scancode) > integer last_index > -- put ASCII key and scan code into buffer > poke( KEY_BUFFER + peek( LAST_INDEX ) - 30, {keycode, scancode} ) > -- adjust pointer > last_index = peek( LAST_INDEX ) > last_index += 2 > if last_index > 60 then > last_index = 30 > end if > poke( LAST_INDEX, last_index ) > end procedure > > </eucode> {{{ > > The comments above are for my own benefit. mainloop() is my main > keypress/mouse event loop. > > I use this in one of my programs which has a very complex input > loop where the program may be in a combination of modes and other > conditions at one time. Some modes are self-contained and only need to > respond to a limited set of keys so they have their own loops which are > called from mainloop(). If they want to pass on some keys which are > normally handled by mainloop(), they call put_key() and return. > > This has a lot of information, including tables of scan code/key code: > http://members.iweb.net.au/~pstorr/pcbook/book3/keyboard.htm > > Bob The code runs fine. Now I can translate some more of my old DOS BASIC programs to Euphoria, so it will just be a matter of time, when my PC will be "BASIC-free".Thanks A LOT to you, Bob, and also to David Cuny! Regards, Juergen