Creating a working SendInput Declare on Windows

Hi Everyone,

This is a work-in-progress of a SendInput declare so that a user can send keyboard keys, mouse input, or hardware input to a program. I have a working program in C++, and am trying to convert it to Xojo. One of the fun puzzles was to retrieve the memory address of a structure: See How to get structure memory address? - #11 by Eugene_Dakin

Working Code in Visual Studio C++ presses the Window Key + D to minimize all windows, which is a relatively harmless program call and shows that the program is working. Here is the C++ code:

There are four input steps, which are: 1) Press the Virtual Win Key, 2) Press the virtual D key, 3) lift the virtual D key, 4) lift the virtual Win Key. The inputs are in an array with a size of 28 bytes. Here is the Microsoft Link to the SendInput function:

Here is the work-in-progress for the SendInput demonstration program in Xojo: SendInputRev1

This is a non-working partial-example. Chuckle, I am trying to convert C++ to Xojo Declares. Sorry for the Xojo spaghetti code, as I am not even close at completing the program.

Its just for fun, and feel free to play with it. :slight_smile:

Your inputs array is the equivalent of a memoryblock of size 28 with 4 INPUT structures laid end to end. You pass that memorblock to SendInput and declare the parameter as Ptr, and Xojo will take care of the rest. I haven’t looked at your code yet, but I think the declare parameters are

(count as Integer, inputs as Ptr, size as Integer)

Call it like

SendInput(4, inputsmemoryblock, 7)

Edit: I’m basing these numbers on reading “The inputs are in an array with a size of 28 bytes” as meaning the total array size is 28 bytes, not that the size of INPUT is 28 bytes.

1 Like

What Tim said, with the addition that Int does not translate to Integer but to Int32, Uint to Uint32.
And just because I am curious: Why are you converting your String variables to Text?

Hi @Tim_Hare , yes, you are correct. I greatly prefer using structures as it makes adding data significantly easier to add and modify, as compared to using a memoryblock and manually counting bytes to modify the information.

I have no problem manually modifying a MemoryBlock to get the example program to work for the first time. Let me play with the code and see what I can create.

There was no reason in particular. I was just trying to show the data on the screen for the first attempt. If I have a hexadecimal number like &h0102E540 then it is likely a memory address, whereas a number like 51 is probably not a memory address. Its just for troubleshooting purposes, thats all. :slight_smile:

Ah yes, I am realizing the error of my ways. After a good night sleep I will rework the example. :slight_smile: