flat assembler
Message board for the users of flat assembler.

Index > Windows > sendinput to keyboard

Author
Thread Post new topic Reply to topic
plaster90



Joined: 03 Jun 2014
Posts: 17
plaster90 08 Jun 2014, 21:39
hi
i wrote simply app to simulation keypress but dosnt work:(
Code:
format PE GUI 4.0
entry start

include 'include\win32ax.inc'

        struct INPUT
               type db 1
               ki.wScan db 0
               ki.time db 0
               ki.dwExtraInfo db 0
               ki.wVk db 'a'
               ki.dwFlags db 0
        ends

        sizeofstruct = $-ip.type

        ip INPUT


start:
        invoke Sleep,2000
        invoke SendInput,1,ip,sizeofstruct
        mov [ip.ki.dwFlags],KEYEVENTF_KEYUP
        invoke SendInput,1,ip,sizeofstruct


koniec:
        invoke ExitProcess,0


section '.idata' import data readable writeable shareable

  library kernel32,     'kernel32.DLL',\
          user32,       'user32.DLL'

          include       'include\api\kernel32.inc'
          include       'include\api\user32.inc' 

    


please help me, I couldnt sleep because of it:(
Post 08 Jun 2014, 21:39
View user's profile Send private message Reply with quote
baldr



Joined: 19 Mar 2008
Posts: 1651
baldr 09 Jun 2014, 01:05
plaster90,

How DWORD type; can be converted to type db 1?
By your definition sizeofstruct==0. Even if you place it below ip INPUT line, all-types-fit-in-byte definition won't get you right size.
plaster90 wrote:
I couldnt sleep because of it
No rest for the wicked. Wink
Post 09 Jun 2014, 01:05
View user's profile Send private message Reply with quote
plaster90



Joined: 03 Jun 2014
Posts: 17
plaster90 09 Jun 2014, 06:16
all right but could you give me some working example ?
I would be grateful Smile
Post 09 Jun 2014, 06:16
View user's profile Send private message Reply with quote
baldr



Joined: 19 Mar 2008
Posts: 1651
baldr 09 Jun 2014, 08:05
plaster90,

This works for me:
Code:
        include "Win32AX.Inc"

struct MOUSEINPUT
        dx              dd ?
        dy              dd ?
        mouseData       dd ?
        dwFlags         dd ?
        time            dd ?
        dwExtraInfo     dd ?
ends

struct KEYBDINPUT
        wVk             dw ?
        wScan           dw ?
        dwFlags         dd ?
        time            dd ?
        dwExtraInfo     dd ?
ends

struct HARDWAREINPUT
        uMsg            dd ?
        wParamL         dw ?
        wParamH         dw ?
ends

struct INPUT
        type            dd ?
        union
                ki      KEYBDINPUT
                mi      MOUSEINPUT
                hi      HARDWAREINPUT
        ends
ends

INPUT_MOUSE             = 0
INPUT_KEYBOARD          = 1
INPUT_HARDWARE          = 2

KEYEVENTF_EXTENDEDKEY   = 1
KEYEVENTF_KEYUP         = 2
KEYEVENTF_UNICODE       = 4
KEYEVENTF_SCANCODE      = 8

        .code
start:  invoke  SendInput, lengthof.inputs, inputs, sizeof.INPUT
        invoke  ExitProcess, 0

        .data
inputs:
irps vk, B A L D R {
        INPUT   INPUT_KEYBOARD, <`vk, 0, 0, 0, 0>
        INPUT   INPUT_KEYBOARD, <`vk, 0, KEYEVENTF_KEYUP, 0, 0>
}
lengthof.inputs = ($-inputs)/sizeof.INPUT

        .end    start    
Post 09 Jun 2014, 08:05
View user's profile Send private message Reply with quote
plaster90



Joined: 03 Jun 2014
Posts: 17
plaster90 09 Jun 2014, 08:20
thx a lot:)
Post 09 Jun 2014, 08:20
View user's profile Send private message Reply with quote
randomdude



Joined: 01 Jun 2012
Posts: 83
randomdude 09 Jun 2014, 08:53
dont forget that if you use:
Code:
struct INPUT 
        type            dd ? 
        union 
                mi     MOUSEINPUT 
                ki      KEYBDINPUT 
                hi      HARDWAREINPUT 
        ends 
ends    


all values will be passed as DWORDs

Code:
        INPUT   INPUT_KEYBOARD, <wVk + wScan shl 16, 0, 0, 0, 0> 
        INPUT   INPUT_KEYBOARD, <wVk + wScan shl 16, KEYEVENTF_KEYUP, 0, 0>    
Post 09 Jun 2014, 08:53
View user's profile Send private message Reply with quote
plaster90



Joined: 03 Jun 2014
Posts: 17
plaster90 09 Jun 2014, 09:16
baldr

works good, but is there a way to dont use macro?
i'm not professional, i'm going to learn macros but this is very hard for me:(
i would be gratefull if you give me this cod witout macros

thanks a lot
Post 09 Jun 2014, 09:16
View user's profile Send private message Reply with quote
baldr



Joined: 19 Mar 2008
Posts: 1651
baldr 09 Jun 2014, 09:41
plaster90,

That irps instant macro expands as a sequence of INPUT …,<character,…> / INPUT …,<character, 0, KEYEVENTF_KEYUP,…> pairs for each given letter:
Code:
        INPUT   INPUT_KEYBOARD, <'B', 0, 0, 0, 0>
        INPUT   INPUT_KEYBOARD, <'B', 0, KEYEVENTF_KEYUP, 0, 0>
        INPUT   INPUT_KEYBOARD, <'A', 0, 0, 0, 0>
        INPUT   INPUT_KEYBOARD, <'A', 0, KEYEVENTF_KEYUP, 0, 0>
        INPUT   INPUT_KEYBOARD, <'L', 0, 0, 0, 0>
        INPUT   INPUT_KEYBOARD, <'L', 0, KEYEVENTF_KEYUP, 0, 0>
        INPUT   INPUT_KEYBOARD, <'D', 0, 0, 0, 0>
        INPUT   INPUT_KEYBOARD, <'D', 0, KEYEVENTF_KEYUP, 0, 0>
        INPUT   INPUT_KEYBOARD, <'R', 0, 0, 0, 0>
        INPUT   INPUT_KEYBOARD, <'R', 0, KEYEVENTF_KEYUP, 0, 0>    
Replace irps with the lines above and you'll get equivalent code.
Post 09 Jun 2014, 09:41
View user's profile Send private message Reply with quote
plaster90



Joined: 03 Jun 2014
Posts: 17
plaster90 09 Jun 2014, 11:17
now it's clear:)
thanks
Post 09 Jun 2014, 11:17
View user's profile Send private message Reply with quote
plaster90



Joined: 03 Jun 2014
Posts: 17
plaster90 11 Jun 2014, 23:11
Hi i got code to past some tekst but it doesn't fully works:(

Code:
format PE GUI 4.0 
entry start 

include 'include\win32ax.inc' 
struct MOUSEINPUT 
        dx              dd ?  
        dy              dd ?  
        mouseData       dd ?  
        dwFlags         dd ?  
        time            dd ?  
        dwExtraInfo     dd ?  
ends 
struct KEYBDINPUT  
        wVk             dw ? 
        wScan           dw ?  
        dwFlags         dd ?  
        time            dd ?  
        dwExtraInfo     dd ?  
ends 
struct HARDWAREINPUT  
        uMsg            dd ?  
        wParamL         dw ?  
        wParamH         dw ?  
ends 
struct INPUT  
        type            dd ?  
        union 
                mi     MOUSEINPUT 
                ki      KEYBDINPUT 
                hi      HARDWAREINPUT 
        ends 
ends 


start: 
        ;invoke Sleep,7000 

        invoke  SendInput,1, inputs1, sizeof.INPUT 
        invoke  SendInput,1, inputs2, sizeof.INPUT 
        invoke  SendInput,1, inputs3, sizeof.INPUT 
        invoke  SendInput,1, inputs4, sizeof.INPUT 


koniec: 
        invoke ExitProcess,0 


inputs1: 

        INPUT   1, <VK_CONTROL, 0, 0, 0, 0> 
inputs2: 
        INPUT   1, <'V', 0,0, 0, 0> 
inputs3: 

        INPUT   3, <'V' 0, KEYEVENTF_KEYUP, 0, 0> 
inputs4: 
        INPUT   4, <VK_CONTROL, 0,KEYEVENTF_KEYUP, 0, 0> 


section '.idata' import data readable writeable shareable 
  library kernel32,     'kernel32.DLL',\ 
          user32,       'user32.DLL' 
          include       'include\api\kernel32.inc' 
          include       'include\api\user32.inc'     


My question is why The program DOESN'T relase the key?Sad
it past tekst but CTRL KEY is still press:(
Post 11 Jun 2014, 23:11
View user's profile Send private message Reply with quote
plaster90



Joined: 03 Jun 2014
Posts: 17
plaster90 12 Jun 2014, 07:37
Hi i got code to past some tekst but it doesn't fully works:(
Code:
format PE GUI 4.0  
entry start  

include 'include\win32ax.inc'  
struct MOUSEINPUT  
        dx              dd ?   
        dy              dd ?   
        mouseData       dd ?   
        dwFlags         dd ?   
        time            dd ?   
        dwExtraInfo     dd ?   
ends  
struct KEYBDINPUT   
        wVk             dw ?  
        wScan           dw ?   
        dwFlags         dd ?   
        time            dd ?   
        dwExtraInfo     dd ?   
ends  
struct HARDWAREINPUT   
        uMsg            dd ?   
        wParamL         dw ?   
        wParamH         dw ?   
ends  
struct INPUT   
        type            dd ?   
        union  
                mi     MOUSEINPUT  
                ki      KEYBDINPUT  
                hi      HARDWAREINPUT  
        ends  
ends  


start:  
        ;invoke Sleep,7000  

        invoke  SendInput,1, inputs1, sizeof.INPUT  
        invoke  SendInput,1, inputs2, sizeof.INPUT  
        invoke  SendInput,1, inputs3, sizeof.INPUT  
        invoke  SendInput,1, inputs4, sizeof.INPUT  


koniec:  
        invoke ExitProcess,0  


inputs1:  

        INPUT   1, <VK_CONTROL, 0, 0, 0, 0>  
inputs2:  
        INPUT   1, <'V', 0,0, 0, 0>  
inputs3:  

        INPUT   3, <'V' 0, KEYEVENTF_KEYUP, 0, 0>  
inputs4:  
        INPUT   4, <VK_CONTROL, 0,KEYEVENTF_KEYUP, 0, 0>  


section '.idata' import data readable writeable shareable  
  library kernel32,     'kernel32.DLL',\  
          user32,       'user32.DLL'  
          include       'include\api\kernel32.inc'  
          include       'include\api\user32.inc'     


My question is why The program DOESN'T relase the key?Sad
it past tekst but CTRL KEY is still press:(
Post 12 Jun 2014, 07:37
View user's profile Send private message Reply with quote
baldr



Joined: 19 Mar 2008
Posts: 1651
baldr 12 Jun 2014, 08:44
plaster90 wrote:
Hi i got code to past some tekst but it doesn't fully works:(
Code:
…
inputs3: 

        INPUT   3, <'V' 0, KEYEVENTF_KEYUP, 0, 0>;;; missing comma after 'V'
inputs4: 
        INPUT   4, <VK_CONTROL, 0,KEYEVENTF_KEYUP, 0, 0>
My question is why The program DOESN'T relase the key?Sad
it past tekst but CTRL KEY is still press:(
The question contains half of an answer. Those 3 and 4, where do you got them? They don't correspond to any of the specified INPUT.type values (INPUT_MOUSE=0, INPUT_KEYBOARD=1, INPUT_HARDWARE=2). Also note that if you place mi MOUSEINPUT before ki KEYBDINPUT in INPUT's definition, then initialization should be done as randomdude mentioned (though it's kludgy).
Post 12 Jun 2014, 08:44
View user's profile Send private message Reply with quote
plaster90



Joined: 03 Jun 2014
Posts: 17
plaster90 12 Jun 2014, 09:42
Sorry baldr. I pasted wrong code. There is
Inputs3:
Input 1 (...)
Inputs4:
Input 1 (...)

And i placed mi MOUSEINPUT bufor ki KEYBOARDINPUT
because its correct in msdn funkcion. Where did i make a mistake? I'd like to write it exacly as msdn function. Will you help?


Last edited by plaster90 on 12 Jun 2014, 09:44; edited 1 time in total
Post 12 Jun 2014, 09:42
View user's profile Send private message Reply with quote
plaster90



Joined: 03 Jun 2014
Posts: 17
plaster90 12 Jun 2014, 10:48
Baldr

Just one more question
This is your code:
Code:
struct INPUT 
        type            dd ? 
        union 
                ki      KEYBDINPUT 
                mi      MOUSEINPUT 
                hi      HARDWAREINPUT 
        ends 
ends 

INPUT_MOUSE             = 0 
INPUT_KEYBOARD          = 1 
INPUT_HARDWARE          = 2 
    


Could you explain me why you Wrote
Code:
INPUT_MOUSE = 0     

so first position in INPUT's struct is
Code:
 ki KEYBDINPUT     

?
Sorry but I don't get it:/

I think it should be:
Code:
ki MOUSEINPUT
mi KEYBDINPUT
    

But This code doesnt work good. ..
Thanks in advance
plaster90
Post 12 Jun 2014, 10:48
View user's profile Send private message Reply with quote
baldr



Joined: 19 Mar 2008
Posts: 1651
baldr 12 Jun 2014, 13:04
plaster90,

The order of the members inside the union usually doesn't matter. In stock fasm macros (Macro/Struct.Inc) there is one caveat: initializer for the union uses definition of its first member, hence if you place mi before ki, values you're providing should correspond to <dx, dy, mouseData, dwFlags, time, dwExtraInfo> respectively. Since KEYBDINPUT starts with two words, wVk and wScan, they map to the single MOUSEINPUT dword, dx (lower and higher 16 bits). Consequently, proper initialization of an INPUT structure with MOUSEINPUT first member within anonymous union should look like
INPUT INPUT_KEYBOARD, <wVk+wScan shl 16, dwFlags, time, dwExtraInfo>.

Order or values of INPUT_* numerical constants are completely unrelated to that.
Post 12 Jun 2014, 13:04
View user's profile Send private message Reply with quote
plaster90



Joined: 03 Jun 2014
Posts: 17
plaster90 12 Jun 2014, 13:21
I must study macros...
If you dont mind, Could give me a the same code sending 'baldr' and then execute MOUSEINPUT for example:
Code:
 invoke SendInput, 1,some, sizeof. INPUT
invoke SendInput, 1,some2, sizeof.INPUT
(......)


some:
INPUT 0,<VK_CONTROL, 0,0,0,0,0>
some2:
INPUT 0,<VK_CONTROL, 0,KEYEVENTF_KEYUP>
    

I would be grateful
Post 12 Jun 2014, 13:21
View user's profile Send private message Reply with quote
baldr



Joined: 19 Mar 2008
Posts: 1651
baldr 12 Jun 2014, 14:40
plaster90,

You're either lazy or not understanding what to do.
Code:
        include "Win32AX.Inc"

struct MOUSEINPUT
        dx              dd ?
        dy              dd ?
        mouseData       dd ?
        dwFlags         dd ?
        time            dd ?
        dwExtraInfo     dd ?
ends

struct KEYBDINPUT
        wVk             dw ?
        wScan           dw ?
        dwFlags         dd ?
        time            dd ?
        dwExtraInfo     dd ?
ends

struct HARDWAREINPUT
        uMsg            dd ?
        wParamL         dw ?
        wParamH         dw ?
ends

struct INPUT
        type            dd ?
        union
                mi      MOUSEINPUT
                ki      KEYBDINPUT
                hi      HARDWAREINPUT
        ends
ends

INPUT_MOUSE             = 0
INPUT_KEYBOARD          = 1
INPUT_HARDWARE          = 2

KEYEVENTF_EXTENDEDKEY   = 1
KEYEVENTF_KEYUP         = 2
KEYEVENTF_UNICODE       = 4
KEYEVENTF_SCANCODE      = 8

MOUSEEVENTF_MOVE        = 1
MOUSEEVENTF_LEFTDOWN    = 2
MOUSEEVENTF_LEFTUP      = 4

        .code
start:  invoke  SendInput, lengthof.inputs, inputs, sizeof.INPUT
        invoke  ExitProcess, 0

        .data
inputs:
        INPUT   INPUT_KEYBOARD, <'B'>
        INPUT   INPUT_KEYBOARD, <'B', KEYEVENTF_KEYUP>
        INPUT   INPUT_KEYBOARD, <'A'>
        INPUT   INPUT_KEYBOARD, <'A', KEYEVENTF_KEYUP>
        INPUT   INPUT_KEYBOARD, <'L'>
        INPUT   INPUT_KEYBOARD, <'L', KEYEVENTF_KEYUP>
        INPUT   INPUT_KEYBOARD, <'D'>
        INPUT   INPUT_KEYBOARD, <'D', KEYEVENTF_KEYUP>
        INPUT   INPUT_KEYBOARD, <'R'>
        INPUT   INPUT_KEYBOARD, <'R', KEYEVENTF_KEYUP>
        INPUT   INPUT_MOUSE, <0, 0, 0, MOUSEEVENTF_LEFTDOWN>
        INPUT   INPUT_MOUSE, <100, 0, 0, MOUSEEVENTF_MOVE>
        INPUT   INPUT_MOUSE, <0, 0, 0, MOUSEEVENTF_LEFTUP>
lengthof.inputs = ($-inputs)/sizeof.INPUT

        .end    start    
Do your mouse really have Ctrl button? Wink
Post 12 Jun 2014, 14:40
View user's profile Send private message Reply with quote
plaster90



Joined: 03 Jun 2014
Posts: 17
plaster90 12 Jun 2014, 15:32
Does anyone know how to send key to keyboard using sendinput funkction, but from this kind of bufor:

Code:
bufor dd ?    
Post 12 Jun 2014, 15:32
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.