Misha Posted May 21, 2008 Posted May 21, 2008 Hi, I am trying to call a SendInput function from user32.dll but I just don't understand what kind of type should I put in, could anyone post an example of a call for it and a use of the function if you can?
Moderators SmOke_N Posted May 21, 2008 Moderators Posted May 21, 2008 Hi, I am trying to call a SendInput function from user32.dll but I just don't understand what kind of type should I put in, could anyone post an example of a call for it and a use of the function if you can?Why would you be using an API call to SendInput and not just Send() from the regular functions that utilizes keybd_event API already?http://msdn.microsoft.com/en-us/library/ms646310(VS.85).aspxhttp://msdn.microsoft.com/en-us/library/ms646270(VS.85).aspxDllCall for the first link and to create the pointer you'll need to use DllStructCreate for the pointer (2nd link). Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.
Misha Posted May 21, 2008 Author Posted May 21, 2008 (edited) Keybd_event fails at working. So I call the struct create and stick the function of it in the type of calls in the sendinput? Somewhat understood. Edited May 21, 2008 by Misha
Misha Posted May 21, 2008 Author Posted May 21, 2008 No..I dont get it, can you give an example for the dllstructcreate?
Moderators SmOke_N Posted May 21, 2008 Moderators Posted May 21, 2008 (edited) No..I dont get it, can you give an example for the dllstructcreate?I'm not sure how AutoIt supports Unions to be honest. You have two structs at any one time you'd have to use.$tagKEYBDINPUT = DllStructCreate("short;short;dword;dword;ulong*") $tagInput = DllStructCreate("dword;uint");Something tells me you need to pass the $tagKEYBDINPUT as a pointer to this struct... 0.oThat of course is without testing and written in here based on the links provided.Edit:IMO, If keybd_event is failing, I seriously can't see SendInput working though. Edited May 21, 2008 by SmOke_N Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.
Misha Posted May 21, 2008 Author Posted May 21, 2008 (edited) Func sendinput($nInputs,$pInput,$cbSize) DllOpen("user32.dll") $tagKEYBDINPUT = DllStructCreate("short;short;dword;dword;ulong*") $tagInput = DllStructCreate("dword;uint",$tagKEYBDINPUT) $return = dllcall("user32.dll","Long","SendInput",$tagInput,$nInputs,$tagKEYBDINPUT,$pInput,"int",$cbSize) Return $return EndFunc SendInput(18,0,1) I tried this blindly since I dont quite understand, wheres my error Oh and I tested it already, sendinput works but keybd/mouse events dont Edited May 21, 2008 by Misha
Moderators SmOke_N Posted May 21, 2008 Moderators Posted May 21, 2008 Func sendinput($nInputs,$pInput,$cbSize)DllOpen("user32.dll")$tagKEYBDINPUT = DllStructCreate("short;short;dword;dword;ulong*")$tagInput = DllStructCreate("dword;uint",$tagKEYBDINPUT)$return = dllcall("user32.dll","Long","SendInput",$tagInput,$nInputs,$tagKEYBDINPUT,$pInput,"int",$cbSize)Return $returnEndFuncSendInput(18,0,1)I tried this blindly since I dont quite understand, wheres my errorOh and I tested it already, sendinput works but keybd/mouse events dontHow did you test it already if you can't even get it to work?I have no idea what you are really doing there, or what you think you are doing.Where did you get 18 for the number of arrays in the input structure?Again, this is not tested... but you didn't create the call to the dll with even the types you were sending it:Local $tagKEYBDINPUT = DllStructCreate("short;short;dword;dword;ulong*") Local $tagInput = DllStructCreate("dword;uint") Return DllCall("user32.dll","Long","SendInput", "uint", $nInputs, "ptr", DllStructGetPtr($tagInput), "int", DllStructGetSize($tagInput)) Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.
Misha Posted May 21, 2008 Author Posted May 21, 2008 (edited) My friend tested it with c++. I truly wonder what the hell am I doing.. Readed it wrongly, understood now and yea, I really don't understand the dll structers so its hard for me to write this, I guess after this is solved I will understand this. func sendinput($nInputs,$pInput,$cbSize) DllOpen("user32.dll") Local $tagKEYBDINPUT = DllStructCreate("short;short;dword;dword;ulong*") Local $tagInput = DllStructCreate("dword;uint") DllStructSetData ($tagKEYBDINPUT, 3,"INPUT_KEYBOARD",) Dllstructsetdata($tagKEYBDINPUT,2,$pInput) Return DllCall("user32.dll","Long","SendInput", "uint", $nInputs, "ptr", DllStructGetPtr($tagInput), "int", DllStructGetSize($tagInput)) endfunc SendInput(1,14,1) still not quite......I added the setdata because I figured i need to specify the type and the actually keyascii so I figured thats how it supposed to be. Edited May 21, 2008 by Misha
Misha Posted May 21, 2008 Author Posted May 21, 2008 (edited) Bump for smoke to wake up ;x Edited May 21, 2008 by Misha
martin Posted May 21, 2008 Posted May 21, 2008 I'm not sure how AutoIt supports Unions to be honest. You have two structs at any one time you'd have to use.Just a comment here on how to deal with a union in AutoIt.$struct1 = DllstructCreate("int;int;")$Struct2 = DllStructCreate("short;short",DllStructGetPtr($Struct1))Then if you read Struct1 you read ints, but if you use struct2 you read shorts. Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Moderators SmOke_N Posted May 21, 2008 Moderators Posted May 21, 2008 Just a comment here on how to deal with a union in AutoIt.$struct1 = DllstructCreate("int;int;")$Struct2 = DllStructCreate("short;short",DllStructGetPtr($Struct1))Then if you read Struct1 you read ints, but if you use struct2 you read shorts.Yeah, I was fairly sure that was it, but my doubt came when I attempted to do that in the above scenario and it failed. Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.
martin Posted May 21, 2008 Posted May 21, 2008 Yeah, I was fairly sure that was it, but my doubt came when I attempted to do that in the above scenario and it failed.Ah, well I'm not brave enough to do it, I just talk about it. Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Misha Posted May 21, 2008 Author Posted May 21, 2008 (edited) I finally understood, looking at the screen last 15 minutes trying to figure it out. The topic went a little off and I am already too tired to solve this further but I shall post it anyway what I thought was right... func sendinput($nInputs,$pInput,$cbSize) DllOpen("user32.dll") Local $tagKEYBDINPUT = DllStructCreate("dword;dword;ulong*") local $Substruct1 = dllstructcreate("short",$tagKEYBDINPUT) local $Substract = dllstructcreate("word;word;dword;dword;ulong*") Local $tagInput = DllStructCreate("dword;uint") DllStructSetData ($Substruct, 1,"INPUT_KEYBOARD",) Dllstructsetdata($Substruct,2,$pInput) Return DllCall("user32.dll","Long","SendInput", "uint", $nInputs, "ptr", DllStructGetPtr($tagInput), "int", DllStructGetSize($tagInput)) endfunc SendInput(1,14,1) If you havent lost interest yet tell me if its correct. Edited May 21, 2008 by Misha
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now