Re: Insert Keycode into Keyboard Buffer?
- Posted by Bob Elia <bobelia200 at netzero.net> May 31, 2004
- 615 views
At 08:09 AM 5/31/2004 +0200, you wrote: > > >cklester wrote: > > > Is it possible to insert a keycode into the keyboard buffer to make it > > look as though that key were actually pressed? > >In the past I did so under DOS, with my programs written in PowerBASIC. >They directly poke() the appropriate values into the BIOS data area. >I tried to translate the appropriate routine to Euphoria, but it didn't >work.>I believe it's because I don't exactly understand, how the Causeway >extender handles memory. > >If you want a Windows program, look for 'sendkeys.zip' by Thomas Parslow >in the archieves. > >Regards, > Juergen This works for DOS32:
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
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