Does anyone know a way of making a program automatically type by itself. Like as soon as you start the program, it starts typing the words instead of just making them appear. I want to put that kind of thing in my program. Does anyone know of a way to do this? I think it would be a nice visual touch. Any examples would be extremely helpul because I have been trying for 3 weeks now to try and implement this using timers and the sleep api and everything.
I did that once with an EditWindow... All I did was (iirc) this:
I don't remember if I also send a WM_KEYUP afterwards... I just played around a bit with the Timer settings and then it looked like someone typed at real speed.
Buffer db "This is some automatic typing",0
...
WM_CREATE
set up a timer
WM_TIMER
mov eax,offset Buffer
xor edx,edx
mov ecx,NextLetter
mov dl,b$[eax+ecx]
or edx,edx
jz done:
invoke SendMessage,hEdit,WM_KEYDOWN,edx,???
inc NextLetter
jmp F:
done:
killtimer
mov NextLetter,0
:
I don't remember if I also send a WM_KEYUP afterwards... I just played around a bit with the Timer settings and then it looked like someone typed at real speed.
you can also use the keybd_event function. this generates an keystroke like pressing a real key
@beaster: but then you have to watch out that your control doesn't lose the focus, it's possible that resistance_is_futile wants to use this effect somewhere on his window, independent of what the user is doing...
resistance_is_futile,
Here is a small example for you,maybe it can be usefull.
.386
.model flat,stdcall
option casemap:none
include \masm32\include\windows.inc
include \masm32\include\user32.inc
include \masm32\include\kernel32.inc
includelib \masm32\lib\user32.lib
includelib \masm32\lib\kernel32.lib
.data
msg db 'Hello my friend!',13,10
db 'What about you?',0
app db 'c:\windows\notepad.exe',0
wndclass db 'Notepad',0
childclass db 'Edit',0
.data?
handle dd ?
.code
start:
invoke WinExec,ADDR app,SW_SHOW
call fndhandle
mov edx,offset msg
restart:
xor eax,eax
mov al,byte ptr
or al,al
jz finish
push edx
invoke SendMessage,handle,WM_CHAR,eax,0
invoke Sleep,500
pop edx
inc edx
jmp restart
finish:
invoke ExitProcess,NULL
fndhandle proc
local temp:dword
invoke FindWindow,addr wndclass,0
mov temp,eax
invoke SetForegroundWindow,eax
invoke FindWindowEx,temp,0,addr childclass,0
mov handle,eax
ret
fndhandle endp
end start
Here is a small example for you,maybe it can be usefull.
.386
.model flat,stdcall
option casemap:none
include \masm32\include\windows.inc
include \masm32\include\user32.inc
include \masm32\include\kernel32.inc
includelib \masm32\lib\user32.lib
includelib \masm32\lib\kernel32.lib
.data
msg db 'Hello my friend!',13,10
db 'What about you?',0
app db 'c:\windows\notepad.exe',0
wndclass db 'Notepad',0
childclass db 'Edit',0
.data?
handle dd ?
.code
start:
invoke WinExec,ADDR app,SW_SHOW
call fndhandle
mov edx,offset msg
restart:
xor eax,eax
mov al,byte ptr
or al,al
jz finish
push edx
invoke SendMessage,handle,WM_CHAR,eax,0
invoke Sleep,500
pop edx
inc edx
jmp restart
finish:
invoke ExitProcess,NULL
fndhandle proc
local temp:dword
invoke FindWindow,addr wndclass,0
mov temp,eax
invoke SetForegroundWindow,eax
invoke FindWindowEx,temp,0,addr childclass,0
mov handle,eax
ret
fndhandle endp
end start