smashly Posted May 18, 2009 Share Posted May 18, 2009 (edited) Hi,Due to my very limited understanding of structs can someone help me to get this INPUT struct in order?MSDN INPUT StructureI didn't understand the 'union' part of the struct and how I use the KEYBDINPUT structure in combination with it.This is the KEYBINPUT struct: MSDN KEYBINPUTThis is the function I'm trying to use it with: MSDN SendInputNon working code exampleGlobal Const $INPUT_KEYBOARD = 1 $KEYBINPUT = DllStructCreate("dword vkCode;dword scanCode;dword flags;dword time;ptr dwExtraInfo") DllStructSetData($KEYBINPUT, 'vkCode', 0x45) ;0x45 = e $nInput = 1 $INPUT = DllStructCreate("dword type;????? ") ; I'm not sure how to add the KEYBINPUT struct $pInput = DllStructGetPtr($INPUT) $cbSize = DllStructGetSize($INPUT) DllCall('user32.dll', 'int', 'SendInput', 'int', $nInput, 'ptr', $pInput, 'int', $cbSize)I'm not in any great need of the SendInput function, it's more like curiosity on how to create the INPUT struct. Edited May 18, 2009 by smashly Link to comment Share on other sites More sharing options...
Authenticity Posted May 18, 2009 Share Posted May 18, 2009 Global Const $KEYEVENTF_KEYUP =2 Global Const $KEYEVENTF_UNICODE = 4 Global Const $INPUT_KEYBOARD = 1 Global Const $tagKEYBDINPUT = _ 'ushort wVk;' & _ 'ushort wScan;' & _ 'dword dwFlags;' & _ 'dword time;' & _ 'ulong_ptr dwExtraInfo' Global Const $tagINPUT = _ 'dword type;' & _ $tagKEYBDINPUT & _ ';dword pad;' & _ 'dword pad'... or an unicode send example -> #682535 Link to comment Share on other sites More sharing options...
Richard Robertson Posted May 18, 2009 Share Posted May 18, 2009 Just take the KEYBDINPUT struct's fields and put them right in place. Link to comment Share on other sites More sharing options...
Authenticity Posted May 18, 2009 Share Posted May 18, 2009 Don't forget that it has to be 28 bytes so you need to pad. That is how union works, you know. Link to comment Share on other sites More sharing options...
smashly Posted May 18, 2009 Author Share Posted May 18, 2009 Thank you for the heads up, I would never have got the input stuct figured stabbing in the dark like I was ..lol Cheers Link to comment Share on other sites More sharing options...
Richard Robertson Posted May 18, 2009 Share Posted May 18, 2009 Union overlaps the data. But also, there is a size parameter, so you might be able to get away with not padding. Link to comment Share on other sites More sharing options...
Authenticity Posted May 18, 2009 Share Posted May 18, 2009 (edited) You mean cbSize, the third parameter? It's still the size of the INPUT struct and not ki's or mi's only so I think that for anything less than the size of the mi struct you need to pad.Edit: One thing is exception. If the size resulting size of the union size is something that is gonna be round to fall on an aligned address then the padding is unnecessary. For example if ki is 14 out of the greatest member of the union which is 16, there will we auto padding. ;] Edited May 18, 2009 by Authenticity Link to comment Share on other sites More sharing options...
Richard Robertson Posted May 18, 2009 Share Posted May 18, 2009 You provide the size of the data you are passing. That's what it's for. Link to comment Share on other sites More sharing options...
smashly Posted May 18, 2009 Author Share Posted May 18, 2009 You provide the size of the data you are passing. That's what it's for.But if I don't pad the INPUT struct then the SendInput function fails and returns 0 Link to comment Share on other sites More sharing options...
Richard Robertson Posted May 18, 2009 Share Posted May 18, 2009 What's the point of the size parameter then? O.o Link to comment Share on other sites More sharing options...
Authenticity Posted May 18, 2009 Share Posted May 18, 2009 Heh, I see you've tested, or not. I guess that inside the function it does something like: if (cbSize != sizeof(INPUT)){ SetLastError(ERROR_INVALID_PARAMETER); return FALSE; } and also for backward compatibility and so the function won't write passing through the allocated memory and for security. .... and I might be very wrong. Link to comment Share on other sites More sharing options...
smashly Posted May 18, 2009 Author Share Posted May 18, 2009 Heh, I see you've tested, or not. ......Yep tested it ..lolAs I said I'd never worked out the struct going via msdn's explanation and my very limited understanding.I would of thought more along the lines of what Richard said about the cbSize until I actually tried and twiddled your code.Thanks you once again. Link to comment Share on other sites More sharing options...
Authenticity Posted May 18, 2009 Share Posted May 18, 2009 You can try and modify $tagINPUT to: Global Const $tagKEYBDINPUT = _ 'ushort wVk;' & _ 'ushort wScan;' & _ 'dword dwFlags;' & _ 'dword time;' & _ 'ulong_ptr dwExtraInfo' Global Const $tagINPUT = _ 'dword type;' & _ $tagKEYBDINPUToÝ÷ ÙKZ)À I believe you'll experience a hard crash or maybe the function is smart enough to not even try it and see if the size of the passed structure is 28. I believe that because it's impossible to know the size of a memory block based on a pointer which in most cases is 4 bytes long is the reason for the cbSize, but this is just assumption. Link to comment Share on other sites More sharing options...
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