Send keyboard keys by ComSend

Hendrik R.
Bad Sassendorf,

Jan 16, 2023
26 Posts

0  |  0  

Re: Send keyboard keys by ComSend

Hi guys,
I want to send different keyboard commands using ComSend procedure.
I also found this post https://www.marvintest.com/Forums/Thread/110/Keyboard-simulation-in-ATEasy-
I have included the library "user32". But I am not able to include the function "keybd_event" correctly. I would appreciate if someone could give me a quick tip on how to include this correctly.
I'm also not sure if my plan works, otherwise is there any other way to send keyboard commands via ComSend?

Thanks for any help,
Hendrik

Solution Available
DrATEasy (Ron Y.)
Mission Viejo, CA

Jan 16, 2023
367 Posts

1  |  0  

Re: Send keyboard keys by ComSend

Hi,

Under procedures of the USER32.dll Library you defined, declare the procedure:

keybd_event(bVk: Val Byte, bScan, : Val Byte, dwFlags: Val DWord, dwExtraInfo : val APointer) : Void

If you are using 32-bit ATEasy, the last parameter can be also Val DWord as a type.

You can also use the SendInput API to (Also defined in User32.dll) send keyboard keys:

https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-sendinput

Declaring DLL function is described in the Help User's Guide, Libraries, Dynamic Link Libraries or in the Getting Started "Working with External Libraries" topic.

Ronnie

Hendrik R.
Bad Sassendorf,

Jan 17, 2023
26 Posts

0  |  0  

Re: Send keyboard keys by ComSend

Hi Ronnie,

Thank you for the help!
I now can run the program, but i receive a memory access violation error.

What have i done?:
- include user32.dll inside of Libraries
- create the procedure -> keybd_event(bVk: Val Byte, bScan : Val Byte, dwFlags: Val DWord, dwExtraInfo : val DWord) : Void
- set user32 library and keybd_event to public
- try to execute -> ComSend(8, "", 0,, system.keybd_event(0x20,0x45,0,0))
- I receive -> "Run-time error #0xC0000005: 'Memory access violation' found in 'SendData' in line 2" which is my line with the ComSend command

To implement the sendinput function, i need to create an array of INPUT structures.
If you look here, there is a union inside the structs.

https://learn.microsoft.com/en-us/windows/win32/api/winuser/ns-winuser-input

How is it possible to implement this function/procedure correctly?

Thanks,
Hendrik

Solution Available
DrATEasy (Ron Y.)
Mission Viejo, CA

Jan 17, 2023
367 Posts

1  |  0  

Re: Send keyboard keys by ComSend

1. The keybd_event does not return anything, so, why are you passing it to ComSend?

   You should get a compiler error for that.

   What data were you expecting to pass to pSrc of ComSend?

2. SendInput issue. Under the Library types declare the INPUT structure, since the INPUT contain union of 3 structures were the biggest structure is 6 DWords (MOUSEINPUT ), you can declare it as 6 DWords.

   INPUT: struct
   {
       DWORD type
       DWORD adwData[6]
   }

Since your need to use the KEYBDINPUT, we will define it so it easy to use:

   INPUT: struct
   {
       DWORD type
       WORD  wVk
       WORD  wScan
       DWORD dwFlags
       DWORD dwTime
       DWORD adwData[3]
   }


Ronnie

Hendrik R.
Bad Sassendorf,

Jan 18, 2023
26 Posts

0  |  0  

Re: Send keyboard keys by ComSend

1. I want to simulate a keystroke and send it to my device via the ComPort.

   Which data do I expect. -> I expect the keystroke, e.g. pressing the space bar, to be sent to my device.

2. Thanks! I will try this.

DrATEasy (Ron Y.)
Mission Viejo, CA

Jan 18, 2023
367 Posts

0  |  0  

Re: Send keyboard keys by ComSend

These procedures (keybd_event, SendInput) will not work for what you need. They are used to send keystrokes to the keyboard and not the other way around.

Please take a look at the ComChat.prj Example. In the example, you will see that keystrokes typed to an edit control are sent to a com port.

Ronnie



Please Note
You need to have a M@GIC account to participate in the Forums.
Not yet registered on our website? Click here to register today!

All content, information and opinions presented on the Marvin Test Solutions User Forums are those of the authors of the posts and messages and not Marvin Test Solutions'. All attachments and files are downloaded at your own risk. [Read More]