News:

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

Send a String with SendInput ( so half) but Working

Started by Zermos, July 10, 2011, 05:24:32 PM

Previous topic - Next topic

Zermos

Can Send each String ( only Normal or with Shift) , is not very good Code , but Working  :lol


I´m a Beginner in Englisch , Assembler und C

Why,  i can not Send with Sendinput 
KEYEVENTF_KEYUP

little confuse












.

include \masm32\include\masm32rt.inc

Send PROTO   :DWORD


;###################### Input Struct ##################################
MOUSEINPUT struct
    _dx         LONG    ?
    _dy         LONG    ?
    mouseData   DWORD   ?
    dwFlags     DWORD   ?
    time        DWORD   ?
    dwExtraInfo PULONG  ?
MOUSEINPUT ends

KEYBDINPUT struct
    wVk         DWORD    ?                          ;now DWord
    wScan       DWORD    ?
    dwFlags     DWORD   ?
    time        DWORD   ?
    dwExtraInfo PULONG  ?
KEYBDINPUT ends

HARDWAREINPUT struct
    uMsg        DWORD   ?
    wParamL     WORD    ?
    wParamH     WORD    ?
HARDWAREINPUT ends

INPUT struct
    dwType      DWORD   ?
    UNION
        mi      MOUSEINPUT <>
        ki      KEYBDINPUT <>
        hi      HARDWAREINPUT <>
    ENDS
INPUT ends
;####################################################################
.const
;constants for dwType
INPUT_MOUSE     equ 0
INPUT_KEYBOARD  equ 1
INPUT_HARDWARE  equ 2




.data
senden db "qqw854gEDRFFtzqqwer",13,10
db "Hello World!",13,10
db '°!"§$%&/()=?`*_:',13,10
db "KEYEVENTF_KEYUP in the SendInput working not correct",13,10
db "~~~~~~~~~~:______------->>>><<<<<°°°°°°",0  ; Can not Send all , Alt Key ist presses



Key  INPUT <INPUT_KEYBOARD,{<0,0,KEYEVENTF_EXTENDEDKEY,0,0>}>
  ;INPUT <INPUT_KEYBOARD,{<0,0,KEYEVENTF_KEYUP,0,0>}>     ; not need KEYEVENTF_KEYUP   <- ist not correct Working
Comment ~

<INPUT_KEYBOARD,{<0,0,KEYEVENTF_EXTENDEDKEY,0,0>}>
  this is :
    wVk         0
    wScan       0
    dwFlags     KEYEVENTF_EXTENDEDKEY      <- u need this for this   VkKeyScan
    time        0
    dwExtraInfo 0
   
    now u need only this
   
    mov Key.ki.wVk,ecx
~

ShiftKey INPUT <INPUT_KEYBOARD,{<VK_SHIFT,0,KEYEVENTF_EXTENDEDKEY,0,0>}> ; this is (N*0)  or Nothings
INPUT <INPUT_KEYBOARD,{<0,0,KEYEVENTF_EXTENDEDKEY,0,0>}>   ; this is (N*1)
INPUT <INPUT_KEYBOARD,{<VK_SHIFT,0,KEYEVENTF_KEYUP,0,0>}> ;<-is not correct working


.code


start:
fn MessageBox,0,"In 10 sek , Send the Text ,now  find fast Notepad ",0,0
invoke Sleep,10000

fn Send,addr senden


invoke ExitProcess,eax






;##################  Funktion Send ##############

Send Proc  pSendInput:DWORD
LOCAL CountLen:DWORD
LOCAL Buffer:DWORD
mov CountLen,0
mov esi,pSendInput 
mov edi,Buffer
N = SIZEOF INPUT

Beginn:
mov ah,[esi]

.if ah==0
jmp Ende
.endif


invoke VkKeyScan , ah     ;;http://msdn.microsoft.com/en-us/library/ms646329(v=vs.85).aspx
movzx ecx,al   ; vkKey
movzx edx,ah ; 0


.if edx == 0 ;nothing normal press key 
mov Key.ki.wVk,ecx
invoke SendInput, 1, ADDR Key, SIZEOF INPUT   ;with SendInput no Shift KEYEVENTF_KEYUP -> what Wrong ?
invoke keybd_event,ecx, 0, KEYEVENTF_KEYUP, 0  ;......

.elseif edx == 1 ; Press shift and Key

mov ShiftKey[N*1].ki.wVk,ecx  ;
invoke SendInput, 3, ADDR ShiftKey, SIZEOF INPUT   ;with SendInput no Shift KEYEVENTF_KEYUP -> what Wrong ?
.if rv(GetAsyncKeyState,VK_SHIFT) !=0 ;http://msdn.microsoft.com/en-us/library/ms646293%28v=VS.85%29.aspx
invoke keybd_event,VK_SHIFT, 0, KEYEVENTF_KEYUP, 0 ; not nice  < --- but now , is better for nothing
.endif
; etc Alt-Key

.endif



inc esi
jmp Beginn
Ende:
invoke Beep, 345,2345



ret
Send EndP






end start



qWord

your struct definition is not correct:
QuoteKEYBDINPUT.wVK => WORD
KEYBDINPUT.wScan => WORD
FPU in a trice: SmplMath
It's that simple!

Zermos

NO - is so correct -   need this für    VkKeyScan , ah    and    mov Key.ki.wVk,ecx


with this   -- only Errors
KEYBDINPUT.wVK => WORD
KEYBDINPUT.wScan => WORD

qWord

Quote from: Zermos on July 10, 2011, 05:41:57 PM
NO - is so correct
No, it is not correct!
KEYBDINPUT struct
    wVk         WORD    ?
    wScan       WORD    ?
    dwFlags     DWORD   ?
    time        DWORD   ?
    dwExtraInfo PULONG  ?
KEYBDINPUT ends
FPU in a trice: SmplMath
It's that simple!

Zermos

Try ist -  become Errors        with DWORD working perfect

qWord

include masm32rt.inc
INPUT_MOUSE             EQU     0
INPUT_KEYBOARD          EQU     1
INPUT_HARDWARE          EQU     2
KEYEVENTF_EXTENDEDKEY   EQU     1
KEYEVENTF_KEYUP         EQU     2
KEYEVENTF_UNICODE       EQU     4
KEYEVENTF_SCANCODE      EQU     8

MOUSEINPUT struct
    _dx         SDWORD  ?
    dy          SDWORD  ?
    mouseData   DWORD   ?
    dwFlags     DWORD   ?
    time        DWORD   ?
    dwExtraInfo DWORD   ?
MOUSEINPUT ends

KEYBDINPUT struct
    wVk         WORD    ?
    wScan       WORD    ?
    dwFlags     DWORD   ?
    time        DWORD   ?
    dwExtraInfo DWORD   ?
KEYBDINPUT ends

HARDWAREINPUT struct
    uMsg        DWORD   ?
    wParamL     WORD    ?
    wParamH     WORD    ?
HARDWAREINPUT ends
INPUT struct
    type_       DWORD   ?
    union
        mi      MOUSEINPUT      <>
        ki      KEYBDINPUT      <>
        hi      HARDWAREINPUT   <>
    ends
INPUT ends
.code
main proc
LOCAL inp:INPUT

    invoke MapVirtualKey,VK_X,0
    mov inp.type_,INPUT_KEYBOARD
    mov inp.ki.wVk,VK_X
    mov inp.ki.wScan,ax
    mov inp.ki.dwFlags,0
    mov inp.ki.time,0
    mov inp.ki.dwExtraInfo,0
    invoke SendInput,1,ADDR inp,SIZEOF INPUT
    invoke ExitProcess,0

main endp
end main

you know that you can use also partial registers?: AX AL/AH,CX,...
FPU in a trice: SmplMath
It's that simple!

Zermos

make it with my Code please ..... i want to know why KEYEVENTF_KEYUP not working



Quoteyou know that you can use also partial registers?: AX AL/AH,CX,...

have try it , but not working (my Code)-> error

#################################

KEYBDINPUT.wVK => WORD
KEYBDINPUT.wScan => WORD

also KEYEVENTF_KEYUP not working   

bomz


qWord

include \masm32\include\masm32rt.inc

Send PROTO   :DWORD

MOUSEINPUT struct
    _dx         LONG    ?
    _dy         LONG    ?
    mouseData   DWORD   ?
    dwFlags     DWORD   ?
    time        DWORD   ?
    dwExtraInfo PULONG  ?
MOUSEINPUT ends

KEYBDINPUT struct
    wVk         WORD    ?
    wScan       WORD    ?
    dwFlags     DWORD   ?
    time        DWORD   ?
    dwExtraInfo PULONG  ?
KEYBDINPUT ends

HARDWAREINPUT struct
    uMsg        DWORD   ?
    wParamL     WORD    ?
    wParamH     WORD    ?
HARDWAREINPUT ends

INPUT struct
    dwType      DWORD   ?
    UNION
        mi      MOUSEINPUT <>
        ki      KEYBDINPUT <>
        hi      HARDWAREINPUT <>
    ENDS
INPUT ends

INPUT_MOUSE     equ 0
INPUT_KEYBOARD  equ 1
INPUT_HARDWARE  equ 2
KEYEVENTF_EXTENDEDKEY   EQU     1
KEYEVENTF_KEYUP         EQU     2
KEYEVENTF_UNICODE       EQU     4
KEYEVENTF_SCANCODE      EQU     8


.data
senden db "qqw854gEDRFFtzqqwer",13,10
db "Hello World!",13,10
db '°!"§$%&/()=?`*_:',13,10
db "KEYEVENTF_KEYUP in the SendInput working not correct",13,10
db "~~~~~~~~~~:______------->>>><<<<<°°°°°°",0  ; Can not Send all , Alt Key ist presses

.code

start:
fn MessageBox,0,"In 10 sek , Send the Text ,now  find fast Notepad ",0,0
invoke Sleep,10000

fn Send,addr senden

invoke ExitProcess,eax


;##################  Funktion Send ##############

Send Proc uses esi edi ebx pSendInput:DWORD
LOCAL inp[2]:INPUT ; two structs: one for pressing the key and one for releasing the key

mov esi,pSendInput 
xor ebx,ebx ; index

N = SIZEOF INPUT

; init structures
mov inp.dwType,INPUT_KEYBOARD
mov inp.ki.dwFlags,0
mov inp.ki.time,0
mov inp.ki.dwExtraInfo,0
mov inp[N].dwType,INPUT_KEYBOARD
mov inp[N].ki.dwFlags,KEYEVENTF_KEYUP
mov inp[N].ki.time,0
mov inp[N].ki.dwExtraInfo,0

.while CHAR ptr [esi+ebx]
.if CHAR ptr [esi+ebx] != 13
mov edi,rv(VkKeyScan,CHAR ptr [esi+ebx])
.if ah & 1
mov inp.ki.wVk,VK_SHIFT
invoke MapVirtualKey,VK_SHIFT,0
mov inp.ki.wScan,ax
invoke SendInput,1,ADDR inp,SIZEOF INPUT
.elseif ah & 2
mov inp.ki.wVk,VK_CONTROL
invoke MapVirtualKey,VK_CONTROL,0
mov inp.ki.wScan,ax
invoke SendInput,1,ADDR inp,SIZEOF INPUT
.elseif ah & 4
mov inp.ki.wVk,VK_MENU
invoke MapVirtualKey,VK_CONTROL,0
mov inp.ki.wScan,ax
invoke SendInput,1,ADDR inp,SIZEOF INPUT
.endif

mov eax,edi
movzx eax,al
mov inp.ki.wVk,ax
mov inp[N].ki.wVk,ax
invoke MapVirtualKey,ax,0
mov inp.ki.wScan,ax
mov inp[N].ki.wScan,ax
invoke SendInput,2,ADDR inp,SIZEOF INPUT

mov eax,edi
.if ah & 1
mov inp[N].ki.wVk,VK_SHIFT
invoke MapVirtualKey,VK_SHIFT,0
mov inp[N].ki.wScan,ax
invoke SendInput,1,ADDR inp[N],SIZEOF INPUT
.elseif ah & 2
mov inp[N].ki.wVk,VK_CONTROL
invoke MapVirtualKey,VK_CONTROL,0
mov inp[N].ki.wScan,ax
invoke SendInput,1,ADDR inp[N],SIZEOF INPUT
.elseif ah & 4
mov inp[N].ki.wVk,VK_MENU
invoke MapVirtualKey,VK_CONTROL,0
mov inp[N].ki.wScan,ax
invoke SendInput,1,ADDR inp[N],SIZEOF INPUT
.endif
.else
; line break
mov inp.ki.wVk,VK_RETURN
mov inp[N].ki.wVk,VK_RETURN
invoke MapVirtualKey,VK_RETURN,0
mov inp.ki.wScan,ax
mov inp[N].ki.wScan,ax
invoke SendInput,2,ADDR inp,SIZEOF INPUT
lea ebx,[ebx+1] ; skip 10
.endif
lea ebx,[ebx+1]
.endw

invoke Beep, 345,2345

ret
Send EndP
end start
FPU in a trice: SmplMath
It's that simple!

Zermos

wow , i can this not understanding good (only little) , its working     thanks


PS . now i understand , is very simple but perfectly

MichaelW

Zermos,

Why are you sending VK_SHIFT with a wScan value of 0 and the KEYEVENTF_EXTENDEDKEY flag?
eschew obfuscation

Zermos

is have working - Beginner : I thinks wScan ist not working when wVk have a value     ( A hardware scan code for the key)why u need this , when u have a Virtual Key