I had a bit of time on my hands so I went ahead and built-tested an Win32 demo. You need to have Notepad open, this program will set the focus to the running Notepad window and send an F1 keystroke which opens the application help.
BITS 32
CPU 386
EXTERN _FindWindowA@8
EXTERN _SetForegroundWindow@4
EXTERN _PostMessageA@16
EXTERN _ExitProcess@4
%define WM_KEYDOWN 0x0100
%define KEY_F(x) (0x6F + x)
SECTION .data
hNotepad: DD 0
strCaption: DB "Untitled - Notepad", 0
strClassName: DB "Notepad", 0
SECTION .text
GLOBAL start
start:
push dword strCaption
push dword strClassName
call _FindWindowA@8
or eax, eax
jz .@@EndIf
mov [hNotepad], eax
push eax
call _SetForegroundWindow@4
xor eax, eax
push eax
push dword KEY_F(1)
push dword WM_KEYDOWN
push dword [hNotepad]
call _PostMessageA@16
.@@EndIf:
xor eax, eax
push eax
call _ExitProcess@4
The build process is as follows:
C:\Project\SendKey>echo %NASMENV%
-IC:\nasm\include\ -Ox -Z.\errors.log
C:\Project\SendKey>nasm -f win32 skey.asm
C:\Project\SendKey>golink /entry:start skey.obj kernel32.dll user32.dll
GoLink.Exe Version 0.26.14 - Copyright Jeremy Gordon 2002/9 - JG@JGnet.co.uk
Output file: skey.exe
Format: win32 size: 2,048 bytes
C:\Project\SendKey>dir
Volume in drive C has no label.
Volume Serial Number is 16A9-4809
Directory of C:\Project\SendKey
04/01/2011 11:24 PM <DIR> .
04/01/2011 11:24 PM <DIR> ..
04/01/2011 11:23 PM 0 errors.log
04/01/2011 11:20 PM 681 skey.asm
04/01/2011 11:24 PM 2,048 skey.exe
04/01/2011 11:23 PM 688 skey.obj
4 File(s) 3,417 bytes
2 Dir(s) 104,286,003,200 bytes free
C:\Project\SendKey>
The settings for %NASMENV% aren't really relevant in this case, however I thought I would post it so nobody would get confused as to why my build left an "errors.log" file in the directory.
Regards,
Bryant Keller