Author Topic: Fn+F6 sendkey  (Read 18127 times)

Offline Binary-Synapse

  • Jr. Member
  • *
  • Posts: 2
Fn+F6 sendkey
« on: April 02, 2011, 01:52:41 AM »
Hello.

How can I use assembly in order to send the key combination Fn+F6 (similar to VB command sendkey)?

Thank you

Offline Frank Kotler

  • NASM Developer
  • Hero Member
  • *****
  • Posts: 2667
  • Country: us
Re: Fn+F6 sendkey
« Reply #1 on: April 02, 2011, 02:08:16 AM »
Dunno. What does the VB command sendkey Fn + F6 do? Sounds like a nonsensical question! This is April first, right? :)

Best,
Frank


Offline Bryant Keller

  • Forum Moderator
  • Full Member
  • *****
  • Posts: 360
  • Country: us
    • About Bryant Keller
Re: Fn+F6 sendkey
« Reply #2 on: April 02, 2011, 02:40:30 AM »
Short answer, you can't. Assembly doesn't have anything like the "SendKey" command. However, the Windows 32-bit API does provide you with SendMessage and the WM_KEYDOWN message. Try something like this:

Code: [Select]
%define WM_KEYDOWN        0x0100
%define KEY_F(x)          (0x6F + x)

... further down ....

push dword 0
push dword KEY_F(4)
push dword WM_KEYDOWN
push dword [hWnd]
extern _SendMessageA@16
call _SendMessageA@16

This code is completely untested, but in theory it should work. I might bring up the winbox later if I feel froggy and try it out.
« Last Edit: April 02, 2011, 02:58:39 AM by Bryant Keller »

About Bryant Keller
bkeller@about.me

Offline Bryant Keller

  • Forum Moderator
  • Full Member
  • *****
  • Posts: 360
  • Country: us
    • About Bryant Keller
Re: Fn+F6 sendkey
« Reply #3 on: April 02, 2011, 03:32:15 AM »
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.

Code: (skey.asm) [Select]
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:

Code: (console) [Select]
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

About Bryant Keller
bkeller@about.me

Offline Binary-Synapse

  • Jr. Member
  • *
  • Posts: 2
Re: Fn+F6 sendkey
« Reply #4 on: April 05, 2011, 09:48:37 PM »
Hello

The question was legit.

I'm trying to simulate the Fn key.

VB, C++, C# have the sendkeys command which can emulate almost any key being pressed.
But some keys like Fn are problematic.
And since Assembly is more low-level, I decided to try it out.

I have only programmed intel 8085, Zilog Z80, and MIPS RISC microprocessors (and to be honest, I can't remember much).
So, no x86 experience and I just downloaded Radasm.

I think everyone got it, but in case they didn't... I'm trying to do something like this VB script:
Code: [Select]
'Open notepad
Set WshShell = WScript.CreateObject("WScript.Shell")
WshShell.Run "notepad"

'Give Notepad time to load (1 second delay)
WScript.Sleep 1000

'Type in Nasm Forums! and then emulate enter key being pressed
WshShell.SendKeys "Nasm Forums!"
WshShell.SendKeys "{ENTER}"

But with Fn Key involved (which is the problematic key).

That's the main problem.

Bryant, I will try your code to see if I can use it (as soon as I have the time).
Or at least to serve me as a jumpstart to a possible solution.

Thank you
« Last Edit: April 05, 2011, 09:50:44 PM by Binary-Synapse »