Page 2 of 3

Re: MS SendInput

Posted: Thu Jul 06, 2017 3:45 am
by Josef Templ
DGDanforth wrote: Some procedures do and others don't use [ccall]
-Doug
OK, there is one exception in WinApi, wsprintf.
It uses ccall because it is defined to use ccall in the corresponding C header file.
This is also documented in msdn.
This function is pretty useless, by the way, because it lacks the vararg parameter. A vararg
cannot be expressed in CP. In C a vararg is a variable number of arguments.
This function also has severe security issues.
It would be a candidate for removal, I think.

- Josef

Re: MS SendInput

Posted: Sat Jul 08, 2017 4:37 am
by DGDanforth
The test program of SendInput works as advertized.
However, it does not work in the context I am using.
I am attempting to send keys to a different process.

I can do that easily using the deprecated function
WinApi.keybd_event
I attach to the process and set its focus.

So why do I need SendInput?
I was hoping it would resolve timing issues of keystroke handling.
Currently with WinApi.keybd_event I need to experimentally determine
the time between a keydown and a keyup (about 65ms). But that should
not be necessary (I believe). I would think that Microsoft and SendInput
would know whether an application is ready to receive input and wait
until it is then send a key. That doesn't seem to be the case. When I
use SendInput it does not fail and yet returns immediately even though
I have specified more than 500 keystrokes.

What must I do to get SendInput to work?
-Doug

Re: MS SendInput

Posted: Tue Jul 11, 2017 11:00 am
by DGDanforth
I discovered that SendInput sends all INPUT records simultaneously (it doesn't wait after sending one INPUT).
That is not what I want.
So, I have broken the array of inputs into individual INPUT and send them sequentially (with a delay).
That still doesn't work for sending to another process.

So I am back using the obsolete function and that works most of the time.
I have not yet found how to delay sending based on whether the process has eaten the previous characters I have sent.
PeekMessage always says there is nothing waiting.

-Doug

Re: MS SendInput

Posted: Tue Jul 11, 2017 12:15 pm
by Josef Templ
Maybe it is required to send both, key-down and key-up events.
Are you sending both?

- Josef

Re: MS SendInput

Posted: Wed Jul 12, 2017 8:48 am
by DGDanforth
Josef Templ wrote:Maybe it is required to send both, key-down and key-up events.
Are you sending both?

- Josef
Yes, first down and then up.

I have also tried SendMessage since it claims to wait until the message is eaten.
Again, I use both down and up but that does not seem work.

Only

Code: Select all

	PROCEDURE KeyDown (key: Key);
	VAR 
		bScan: SHORTCHAR;
		dwFlags: SET;
		dwExtraInfo: INTEGER;
		tkey:	Key;
	BEGIN
		tkey :=TranslateKey(key);
		bScan := 0X; (*SHORT(CHR(WinApi.MapVirtualKey(ORD(tkey), 0)));*)
		dwFlags := {};
		dwExtraInfo := 0;
		WinApi.keybd_event (tkey, bScan, dwFlags, dwExtraInfo)
	END KeyDown;
	
	PROCEDURE KeyUp (key: Key);
	VAR 
		bScan: SHORTCHAR;
		dwFlags: SET;
		dwExtraInfo: INTEGER;
		tkey:	Key;
	BEGIN
		tkey :=TranslateKey(key);
		bScan := 0X; (*SHORT(CHR(WinApi.MapVirtualKey(ORD(tkey), 0)));*)
		dwFlags := WinApi.KEYEVENTF_KEYUP;
		dwExtraInfo := 0;
		WinApi.keybd_event (tkey, bScan, dwFlags, dwExtraInfo)
	END KeyUp;
works (most of the time). TranslateKey simply maps "R" to a right move key, etc.

Re: MS SendInput

Posted: Thu Jul 13, 2017 2:12 pm
by Josef Templ
with SendInput there is the requirement that the other process is at the same security level,
whatever that means in detail, but this is documented in msdn.
Maybe that is the problem why SendInput does not work.

- Josef

Re: MS SendInput

Posted: Sat Jul 15, 2017 6:32 am
by DGDanforth
Josef Templ wrote:with SendInput there is the requirement that the other process is at the same security level,
whatever that means in detail, but this is documented in msdn.
Maybe that is the problem why SendInput does not work.

- Josef
Yes, I noticed that.
I am not sure how to determine the security level (have you yet looked into the issue)
- Doug

Re: MS SendInput

Posted: Sat Jul 15, 2017 11:30 am
by Josef Templ
I can use SendInput to send a keystroke to another BlackBox process.
At least in this case sending a key-down is sufficient.
Check if the receiving process has the focus.

- Josef

Re: MS SendInput

Posted: Sun Jul 16, 2017 10:00 am
by DGDanforth
Josef Templ wrote:I can use SendInput to send a keystroke to another BlackBox process.
At least in this case sending a key-down is sufficient.
Check if the receiving process has the focus.

- Josef
to another BlackBox process
In my case the other process is a game.
Yes, it has the focus.
Let me try it again with SendInput.
- Doug

Re: MS SendInput

Posted: Sun Jul 16, 2017 10:39 am
by DGDanforth
Josef,
The game does not respond even when I put a 500ms delay between the down and the up.
The game has the focus when I am sending.

Code: Select all

WinApi.Sleep(sleepTime);
SendInput returns a non zero result indicating success.
-Doug