flat assembler
Message board for the users of flat assembler.

Index > Windows > VB - > ASM emulate SendKeys

Author
Thread Post new topic Reply to topic
r22



Joined: 27 Dec 2004
Posts: 805
r22 10 Mar 2005, 02:21
Emulating sendkeys does not involve using the sendmessage wm_settext window API.
For this sample I will be using two API's found in user32.dll
I will assume you already have the window handle for the program you want to emulate keystrokes to.

Code:
keybd_event
SetForegroundWindow

.data
StrToSend db 'Hello NotePad',0

.code
..Start:
push ebp
mov ebp,esp

push [WindowHandle]
call [SetForegroundWindow]

push StrToSend
call SendKeys

mov esp,ebp
pop ebp
ret 0

SendKeys:
.theStr equ ebp-8
  push ebp
  mov ebp,esp
  push esi
  mov esi, [.theStr]
.LoopToNull:
  cmp byte[esi],0
  je .AllDone
  movzx eax,byte[esi]
  push eax ;save it for 2nd call

  push 0 ;extra info
  push 1 ;flag
  push 0 ;key ScanCode
  push eax ;Virtual Keycode using ASCII
  call [keybd_event]
  pop eax ;get saved VK code
  push 0 ;extra info
  push 3 ;flags for key UP
  push 0 ;scan code
  push eax ;VK Code
  call [keybd_event]

  add esi,1
  jmp .LoopToNull
.AllDone:
  pop esi
  mov esp,ebp
  pop ebp
  ret 4    


That is a better SendKey emulation.

moderator says: please use teh [ code ] tags.
Post 10 Mar 2005, 02:21
View user's profile Send private message AIM Address Yahoo Messenger Reply with quote
Madis731



Joined: 25 Sep 2003
Posts: 2139
Location: Estonia
Madis731 11 Mar 2005, 10:14
It's all fun and interesting, but please, use [ code] tags
Code:
;to help others read better    
[ /code]
Thank you!
Post 11 Mar 2005, 10:14
View user's profile Send private message Visit poster's website Yahoo Messenger MSN Messenger Reply with quote
r22



Joined: 27 Dec 2004
Posts: 805
r22 16 Mar 2005, 06:20
Everyone's a critic Razz
Post 16 Mar 2005, 06:20
View user's profile Send private message AIM Address Yahoo Messenger Reply with quote
null



Joined: 03 Jan 2005
Posts: 2
Location: massachusetts
null 20 Apr 2005, 03:04
lol Smile hi

_________________
::as water fills the lungs, light empties the mind::
Post 20 Apr 2005, 03:04
View user's profile Send private message Visit poster's website Reply with quote
BigVent



Joined: 28 May 2008
Posts: 24
BigVent 28 May 2008, 13:40
r22,

I really appreciate the code provided. Could you elaborate to a newb on what this does and what I can do with this.

I'm trying to make a program that will interact with my remote login (give password to login screen), then click three buttons and exit.

Any help is appreciated!!!
Post 28 May 2008, 13:40
View user's profile Send private message Reply with quote
asmhack



Joined: 01 Feb 2008
Posts: 431
asmhack 28 May 2008, 15:17
BigVent wrote:
r22,

I really appreciate the code provided. Could you elaborate to a newb on what this does and what I can do with this.

I'm trying to make a program that will interact with my remote login (give password to login screen), then click three buttons and exit.

Any help is appreciated!!!


Code:
invoke keybd_event,VK_NUMLOCK,0,KEYEVENTF_EXTENDEDKEY or 0,0
invoke keybd_event,VK_NUMLOCK,0,KEYEVENTF_EXTENDEDKEY or KEYEVENTF_KEYUP,0
    


virtual key codes:
http://msdn.microsoft.com/en-us/library/ms927178.aspx
Post 28 May 2008, 15:17
View user's profile Send private message Reply with quote
BigVent



Joined: 28 May 2008
Posts: 24
BigVent 28 May 2008, 15:36
Thank you asmhack!

--edit--

By chance... do you have an example program that will pass a pre-defined password to current window?

-- End edit--

~BIgVent
Post 28 May 2008, 15:36
View user's profile Send private message Reply with quote
asmhack



Joined: 01 Feb 2008
Posts: 431
asmhack 28 May 2008, 15:52
well the above code will send keys to foreground/focused edit box for example, the other way is to obtain hwnd (handle of the edit box) and use SetWindowText api function
Post 28 May 2008, 15:52
View user's profile Send private message Reply with quote
bitRAKE



Joined: 21 Jul 2003
Posts: 4046
Location: vpcmpistri
bitRAKE 29 May 2008, 01:43
Maybe something like:
Code:
     push esi
    mov esi,StrToSend

       push [WindowHandle]
 call [SetForegroundWindow]

SendKeys:
     lodsb
       movzx ecx,al
        jecxz .AllDone

  push 0          ; extra info
        push 3          ; flags for key UP
  push 0          ; scan code
 push ecx        ; VK Code

       push 0          ; extra info
        push 1          ; flag
      push 0          ; key ScanCode
      push ecx        ; Virtual Keycode using ASCII

   call [keybd_event]

      call [keybd_event]

      jmp SendKeys

.AllDone:
   pop esi
     retn    
Idea Not really an emulation of SendKeys anymore.

(all those extra instructions just make my head hurt, lol)

_________________
¯\(°_o)/¯ “languages are not safe - uses can be” Bjarne Stroustrup
Post 29 May 2008, 01:43
View user's profile Send private message Visit poster's website 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.