Jump to content

struct INPUT ?


Recommended Posts

Hi,

Due to my very limited understanding of structs can someone help me to get this INPUT struct in order?

MSDN INPUT Structure

I 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 KEYBINPUT

This is the function I'm trying to use it with: MSDN SendInput

Non working code example

Global 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 by smashly
Link to comment
Share on other sites

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

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 by Authenticity
Link to comment
Share on other sites

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

Heh, I see you've tested, or not. ......

Yep tested it ..lol

As 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

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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...