News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

SendInput

Started by ragdog, May 01, 2011, 03:34:24 PM

Previous topic - Next topic

MichaelW

It was worth a try, but in my code "word ptr VK_NUMLOCK" was accepted but did not correct the problem with the order of the structures in the union.

eschew obfuscation

dedndave

this assembles without error
        .NOLIST
        .XCREF
        INCLUDE \masm32\include\masm32rt.inc
        .586
        .LIST

;---------------------------------

MOUSEINPUT    STRUCT    ;24 bytes
  _dx         dd ?
  _dy         dd ?
  mouseData   dd ?
  dwFlags     dd ?
  time        dd ?
  dwExtraInfo dd ?
MOUSEINPUT    ENDS

KEYBDINPUT    STRUCT    ;16 bytes
  wVk         dw ?
  wScan       dw ?
  dwFlags     dd ?
  time        dd ?
  dwExtraInfo dd ?
KEYBDINPUT    ENDS

HARDWAREINPUT STRUCT    ;8 bytes
  uMsg        dd ?
  wParamL     dw ?
  wParamH     dw ?
HARDWAREINPUT ENDS

INPUT         STRUCT    ;28 bytes
  dwType      dd ?
  UNION
    mi MOUSEINPUT    <>
    ki KEYBDINPUT    <>
    hi HARDWAREINPUT <>
  ENDS
INPUT         ENDS

;---------------------------------

        .DATA

kia LABEL INPUT
dd INPUT_KEYBOARD                         ;dwType, control key down
dw VK_CONTROL                             ;wVk = VK_CONTROL
dw 0                                      ;wScan
dd 0                                      ;dwFlags = key down
dd 0                                      ;time
dd 0                                      ;dwExtraInfo
dd 0,0                                    ;pad

dd INPUT_KEYBOARD                         ;dwType, "g" key down
dw 0                                      ;wVk
dw 47h                                    ;wScan = "g"
dd KEYEVENTF_SCANCODE                     ;dwFlags = key down
dd 0                                      ;time
dd 0                                      ;dwExtraInfo
dd 0,0                                    ;pad

dd INPUT_KEYBOARD                         ;dwType, "g" key up
dw 0                                      ;wVk
dw 47h                                    ;wScan = "g"
dd KEYEVENTF_SCANCODE or KEYEVENTF_KEYUP  ;dwFlags = key up
dd 0                                      ;time
dd 0                                      ;dwExtraInfo
dd 0,0                                    ;pad

dd INPUT_KEYBOARD                         ;dwType, control key up
dw VK_CONTROL                             ;wVk = VK_CONTROL
dw 0                                      ;wScan
dd KEYEVENTF_KEYUP                        ;dwFlags = key up
dd 0                                      ;time
dd 0                                      ;dwExtraInfo
dd 0,0                                    ;pad

        .CODE

_main   PROC

;        INVOKE  SetFocus,hWin
        INVOKE  SendInput,4,offset kia,sizeof INPUT
        INVOKE  ExitProcess,0

_main   ENDP

        END     _main


now, to put it in a test program   :P

dedndave

 :bg


if you make another structure array for extended keys, i think you can use the same two arrays to synthesize any key entry

which brings up another point...
don't write code that assumes the user can only type 200 wpm   :lol

ragdog

Thanks @all

@dedndave

What if this for a tool os info Dump?

dedndave

it's a project i have been working on for some time
i am updating my OS Info Dump program - here is the old one.....
http://www.masm32.com/board/index.php?topic=11963.msg90835#msg90835
that was a console app

i wanted to learn GUI programming, so this is fancier than it needs to be for OS Info   :P
i am almost ready to post the OS Info Dump 3.0 - a few things to fix
i will post the source code when i do
along the way, i wanted to learn about windows messages, so i wrote some code that will display WM messages
i just happened to have it set up like that, so it was easy to add the SendInput code for testing

i have a future project in mind that i can use the GUI text window for   :bg

ragdog

Nice tool

I have already your old os dump
But i see you can look with your new version on windows messages :U

Ok i wait if you upload your new version

Greate Job

dedndave

that really isn't part of the OS Info program - lol
i added that in as an include file so that i could learn about windows messages
http://www.masm32.com/board/index.php?topic=16460.msg137899#msg137899

i have a few things to fix before i post the OS Info program
but, if you want a program to view messages, Winspector is much more robust
http://www.softpedia.com/get/Security/Security-Related/Winspector.shtml

dedndave

well - it looks like the code still needs a little work
i added WM_CHAR to the message filter
then, ran the program again - no WM_CHAR message   :red



lines 1-4 represent the programatic keystroke using SendInput
lines 5-9 represent the manual keystroke sequence
i don't understand why it generates a "G" when i pressed "g" - caps lock is off   :bg

dedndave

if the "right" way doesn't work, cheat   :bg



        .DATA

KyTable dd WM_KEYDOWN,VK_CONTROL,1D0001h
        dd WM_KEYDOWN,'G',220001h
        dd WM_CHAR,7,220001h
        dd WM_KEYUP,'G',0C0220001h
        dd WM_KEYUP,VK_CONTROL,0C01D0001h

        .CODE

        push    ebx
        push    esi
        push    edi
        mov     ebx,hWin
        push    5
        INVOKE  SetFocus,ebx
        mov     edi,offset KyTable
        pop     esi

kLoop0: INVOKE  SendMessage,ebx,[edi],[edi+4],[edi+8]
        add     edi,12
        dec     esi
        jnz     kLoop0

        pop     edi
        pop     esi
        pop     ebx


of course, that does not go through the systems' key filter
it does not generate a Bell character
you might try sending chr$(7), or.....
        INVOKE  Beep,1000,100
:bg