1. Insert Keycode into Keyboard Buffer?

Is it possible to insert a keycode into the keyboard buffer to make it
look as though that key were actually pressed?

new topic     » topic index » view message » categorize

2. Re: Insert Keycode into Keyboard Buffer?

cklester wrote:
> 
> Is it possible to insert a keycode into the keyboard buffer to make it
> look as though that key were actually pressed?

I had to go all the way back to July 2001, but I found "SendKeys()" from
PatRat! It's probably just what I need!!! :)

new topic     » goto parent     » topic index » view message » categorize

3. Re: Insert Keycode into Keyboard Buffer?

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. sad
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

new topic     » goto parent     » topic index » view message » categorize

4. Re: Insert Keycode into Keyboard Buffer?

On Sun, 30 May 2004 20:29:43 -0700, cklester <guest at RapidEuphoria.com>
wrote:

>Is it possible to insert a keycode into the keyboard buffer to make it
>look as though that key were actually pressed?
>
I've used this successfully under Windows 98 / win32lib,
can't remember where I got it from:

constant KEYEVENTF_KEYUP = #02
atom user32, xkeybd_event, initKB
							initKB=0

procedure keybd(integer character)
-- simulate a key press (and release!).
-- character may be literal or a virtual key (eg VK_HOME)
	if not initKB then
		user32=open_dll("user32.dll")
		xkeybd_event = define_c_proc(user32,
"keybd_event",{C_LONG,C_LONG,C_LONG,C_LONG})
		initKB=1
	end if
	c_proc(xkeybd_event,{character,0,0,0})
	c_proc(xkeybd_event,{character,0,KEYEVENTF_KEYUP,0})
end procedure


Not that you asked for it, but while I'm here, I also used this:

procedure clickPointer(object dwFlags)
	if sequence(dwFlags) then dwFlags=or_all(dwFlags) end if
	w32Proc(xmouse_event,{dwFlags,0,0,0,0})
end procedure

eg:
		if action=M_Left then
			clickPointer(MOUSEEVENTF_LEFTDOWN+MOUSEEVENTF_LEFTUP)
		end if

To simulate mouse events, along with getPointerPos/setPointerPos.

Regards,
Pete

new topic     » goto parent     » topic index » view message » categorize

5. Re: Insert Keycode into Keyboard Buffer?

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. sad
>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

new topic     » goto parent     » topic index » view message » categorize

6. Re: Insert Keycode into Keyboard Buffer?

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". blink
Thanks A LOT to you, Bob, and also to David Cuny!

Regards,
   Juergen

new topic     » goto parent     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu