Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Sample for SendInput() ?

220 views
Skip to first unread message

Gerhard Bunzel

unread,
Jul 30, 2018, 7:38:07 AM7/30/18
to
Hello,

for a phone dial by our app, we have to do a keyboard simulation.
Therefor I found the WIN32 function SendInput(). Has somebody a sample
with VO to do this?

Thanks in advance.

Best regards

Gerhard Bunzel

Jamal

unread,
Jul 30, 2018, 12:56:06 PM7/30/18
to
Hi Gerhard,

If you are familiar with C#, you can create a COM component using
InputSimulator NUGet package which then you can call from VO. I only tested
it under C#.

Reference:
https://ourcodeworld.com/articles/read/520/simulating-keypress-in-the-right-way-using-inputsimulator-with-csharp-in-winforms

HTH,
Jamal



Jamal

"Gerhard Bunzel" wrote in message news:pjmtau$dk5$1...@news-1.m-online.net...

Karl Wochele

unread,
Jul 31, 2018, 1:33:24 AM7/31/18
to
Hi Gerhard,

we use this function:

FUNCTION KeyBoard_Event(nKey)
LOCAL aKeys AS ARRAY
LOCAL n AS DWORD

IF IsArray(nKey)
aKeys := nKey
ELSE
aKeys := {nKey}
ENDIF

FOR n := 1 UPTO ALen(aKeys)
keybd_event(aKeys[n],0,0,0)
NEXT n
FOR n := ALen(aKeys) DOWNTO 1
keybd_event(aKeys[n],0,KEYEVENTF_KEYUP,0)
NEXT n


/*
// Simulating a Alt+Tab keystroke
keybd_event(VK_MENU,0xb8,0 , 0); //Alt Press
keybd_event(VK_TAB,0x8f,0 , 0); // Tab Press
keybd_event(VK_TAB,0x8f, KEYEVENTF_KEYUP,0); // Tab Release
keybd_event(VK_MENU,0xb8,KEYEVENTF_KEYUP,0); // Alt Release

// Simulating a Ctrl+A keystroke
keybd_event(VK_CONTROL,0x9d,0 , 0); // Ctrl Press
keybd_event(VkKeyScan(‘A’),0x9e,0 , 0); // ‘A’ Press
keybd_event(VkKeyScan(‘A’),0x9e, KEYEVENTF_KEYUP,0); // ‘A’ Release
keybd_event(VK_CONTROL,0x9d,KEYEVENTF_KEYUP,0); // Ctrl Release
*/

RETURN NIL


HTH
Karl

Gerhard Bunzel

unread,
Jul 31, 2018, 5:57:23 AM7/31/18
to
Hi Jamal,

thanks for your info.

SendInput() is available as WIN32-API without .NET and C#.
So i prefer a solution without .NET.

Thanks

Best regards

Gerhard

Gerhard Bunzel

unread,
Jul 31, 2018, 6:04:01 AM7/31/18
to
Hi Karl,

thanks for your answer.

I know that funktion Keybd_event() and it is very easy to use.

That info is from Microsoft Dev Center about keybd_event()
Note: This function has been superseded. Use SendInput instead.

So I look for a solution with SendInput().

Thanks

Best regards

Gerhard

Karl-Heinz

unread,
Jul 31, 2018, 10:00:32 AM7/31/18
to
Hi Gerhard,

> for a phone dial by our app, we have to do a keyboard simulation.
> Therefor I found the WIN32 function SendInput(). Has somebody a sample
> with VO to do this?

it seems that it´s neccesarry to create a UNION. Here´s what i did so far:

UNION _UnionSendInput
MEMBER mi IS _WINMOUSEINPUT
MEMBER ki IS _winKEYBDINPUT
MEMBER hi IS _winHARDWAREINPUT

STRUCTURE _winINPUT
MEMBER type AS DWORD
MEMBER Input IS _UnionSendInput // <-------

/*
MEMBER mi IS _WINMOUSEINPUT
MEMBER ki IS _winKEYBDINPUT
MEMBER hi IS _winHARDWAREINPUT
*/

STRUCTURE _winHARDWAREINPUT
MEMBER uMsg AS DWORD
MEMBER wParamL AS WORD
MEMBER wParamH AS WORD

STRUCTURE _winKEYBDINPUT
MEMBER wVk AS WORD
MEMBER wScan AS WORD
MEMBER dwFlags AS DWORD
MEMBER time AS DWORD
MEMBER dwExtraInfo AS _WINULARGE_INTEGER // ULONG_PTR ???

STRUCTURE _WINMOUSEINPUT
MEMBER dx AS LONG
MEMBER dy AS LONG
MEMBER mouseData AS DWORD
MEMBER dwFlags AS DWORD
MEMBER time AS DWORD
MEMBER dwExtraInfo AS _WINULARGE_INTEGER // ULONG_PTR ????

DEFINE INPUT_MOUSE := 0 // The event IS a mouse event. Use the mi STRUCTURE
OF the UNION.
DEFINE INPUT_KEYBOARD := 1 // The event IS a keyboard event. Use the ki
STRUCTURE OF the UNION.
DEFINE INPUT_HARDWARE := 2 // The event is a hardware event. Use the hi
structure of the union.


_DLL FUNCTION SendInput ( nInputs AS DWORD , pInputs AS _winINPUT , cbSize
AS INT ) AS DWORD PASCAL:User32.SendInput

-----------------------------------

about the dwExtraInfo member i´m not sure if it´s correct, but at least this
sample works for me. It opens here a Submenu via

<Alt> + L. Without using the UNION SendInPut() fails with the errorcode
87 -> ERROR_INVALID_PARAMETER

----------------------

FUNCTION TestKeyboardSendInPut() AS VOID
LOCAL ip IS _winINPUT
LOCAL dwError AS DWORD


ip.type := INPUT_KEYBOARD
ip.Input.ki.wScan := 0
ip.Input.ki.time := 0
ip.Input.ki.dwExtraInfo := 0

// -----------------------

// Press "Alt" key
ip.Input.ki.wVk := VK_MENU
ip.Input.ki.dwFlags := 0 // 0 for key press
SendInput(1, @ip, _SIZEOF( _winINPUT))

// Press "L" key
ip.Input.ki.wVk := WORD ( Asc ( "L" ))
ip.Input.ki.dwFlags := 0 // 0 for key press
SendInput(1, @ip, _SIZEOF( _winINPUT))

// Release the "L" key
ip.Input.ki.wVk := WORD ( Asc ( "L" ) )
ip.Input.ki.dwFlags := KEYEVENTF_KEYUP
SendInput(1, @ip, _SIZEOF( _winINPUT))

// Release the "Alt" key
ip.Input.ki.wVk := VK_MENU
ip.Input.ki.dwFlags := KEYEVENTF_KEYUP
IF SendInput(1, @ip, _SIZEOF( _winINPUT)) == 0

dwError := GetLastError()

MsgInfo ( NTrim ( dwError ) + crlf + ErrString ( dwError ) )

ENDIF

//


RETURN



regards
Karl-Heinz



Karl-Heinz

unread,
Jul 31, 2018, 10:11:32 AM7/31/18
to
Hi Gerhard,

> for a phone dial by our app, we have to do a keyboard simulation.
> Therefor I found the WIN32 function SendInput(). Has somebody a sample
> with VO to do this?

sample works for me. It opens here a Submenu via <Alt> + <L>. Without using
RETURN

---------------

regards
Karl-Heinz

Jamal

unread,
Jul 31, 2018, 3:00:25 PM7/31/18
to
>> about the dwExtraInfo member i´m not sure if it´s correct <<

ULONG_PTR is defined as DWORD_PTR, so:

Maybe: MEMBER dwExtraInfo as DWORD PTR

Source:
https://docs.microsoft.com/en-us/windows/desktop/winprog/windows-data-types

Jamal

"Karl-Heinz" wrote in message news:fsb90i...@mid.individual.net...

Gerhard Bunzel

unread,
Aug 2, 2018, 3:00:52 AM8/2/18
to
Hi Karl-Heinz,

...thanks for that sample - works perfect.

Thaks again.

Best regards

Gerhard
0 new messages