News:

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

sending keys to a browser?

Started by rafaly, April 23, 2009, 06:31:29 PM

Previous topic - Next topic

rafaly

Hi

I have downloaded the autotype example from vortex and with some modifications I was able to make a new app which opens the command box and sends keystrokes to it.

However when I try to do the same with firefox it won't work.

Anyone knows why? I am thinking it won't process the same way the WM_CHAR messages we send? in that case how else could we implement this autotype for a browser like firefox?

Thanks :thumbu

Vortex

There are multiple handles associated with the window class MozillaWindowClass What are you trying to achieve exactly?

rafaly

I am trying to do automated tasks in firefox, for instance , entering the facebook site and then typing my username and password, but it seems it won't receive the keys. And I have tried using FindWindow, addr classname, 0 using MozillaWindowClass or MozillaUIWindowClass, both won't work and I don't know why.

I really like your autotype by the way! I was thinking about making an app like that and searched a little here just to find out that it was already invented! So well done  :U

UtillMasm

you need a keyboard & mouse spirit!
do you use it to game WoW! :lol

Mark Jones

"Scripting" commands to a browser has the potential to be abused... (think "bots.") However an alternative may be to make a plugin for the browser, which could do pretty much anything desired. Netscape/Mozilla/FireFox/K-Meleon (and others) are based on the Gecko engine, so writing an "NP-plugin" for this core will work for any of those browsers.

For more information (warning, C++ ahead), please see:
https://developer.mozilla.org/En/Gecko_SDK

NOTE: I was unable to get the latest Gecko SDK to compile any example with the latest mozilla source. (Both must be downloaded.) Part of the reason could be this. Soon I will try the Gecko 1.8 SDK and corresponding mozilla source (which should work) and report my findings. (I intended to make a MASM or GoASM version of the SDK, but we'll see...)
"To deny our impulses... foolish; to revel in them, chaos." MCJ 2003.08

dedndave

Come to think of it, you may be able to browse through the already existing Firefox extensions and find something that will help you do what you want.
Autofill comes to mind. Also, these extension "XPI" files are actually ZIP files - just rename. You may be able to use this to learn how to access FF.

farrier

rafaly,

On my Vista 64 machine, FindWindow fails unless you run the program trying to do the FindWindow as "Administrator"  This is apparently to "protect" you.  You don't have to "run" as Admin, but the program doing the FindWindow has to be "Run As Administrator"

hth,

farrier
It is a GOOD day to code!
Some assembly required!
ASM me!
With every mistake, we must surely be learning. (George...Bush)

drhowarddrfine

Since Internet Explorer is build into the OS, it might make this easier than other browsers which don't have such privileges. Add-ons/extensions are written in javascript with XML but I don't know if they apply to what you want. But it might. Look into XUL on the Mozilla site, and particularly  with Ubiquity. Some truly amazing stuff can happen with those tools but I haven't a clue how you'd tie those in to your masm code.

rafaly

Ok thanks for the tips, I am guessing I will now try to do it with FindWindow and FindWindowEx since as pointed by vortex there are many handles for the firefox app already.

haven't tried IE though, thinking it might be a good idea, although I like boycotting IE just like you  :bg

and yes I am running as admin already so it's probably something else.

take care all

Rainstorm

hi, this is interesting.. I use seamonkey most of the while,..would be interested to know how , if you figure it out using the winAPI

laters

jj2007

Quote from: rafaly on April 24, 2009, 01:01:56 PM
I am trying to do automated tasks in firefox, for instance , entering the facebook site and then typing my username and password, ...

Sounds like a modest agenda. One option is DDE, but it is not that easy. By the way: You don't see the message "Do you want Firefox to remember your login and password"??

Have you tried a shortcut containing the http://username:password@facebook.com syntax?

rafaly

Yeah, I admit there are other ways to do that, and I am doing it more just for fun than for some real need... just for the challenge - but that said, I thought it would be something really easy to do in asm!

But it seems to be actually very complex  :eek

So, yes, nevermind, I don't really have that much of a need to do this, anyway I'd like to thank all the nice folks that were giving suggestions in here :)

Good weekend!

Vortex

rafaly,

It may not be the best idea but did you try to simulate keystrokes with the function keybd_event?

rafaly

Yes thanks! it actually worked this way. :)

I tried to make a new AutoType function based on yours but changing the SendMessage part to the keybd_event needed .

The difference is that with this one, the window has to be the one in focus always, and also some issues with characters will appear,I have to make my strings all in capital letters for them to be recognized, i'm still trying to figure out how some characters can be sent (like the "@" )

so here is your autotype, modified for use with keybd_event, but with the issues I described - cannot figure yet how to send these special characters

;=================================================
.386
.model flat,stdcall
option casemap:none

include     \masm32\include\windows.inc
include     \masm32\include\kernel32.inc
include     \masm32\include\user32.inc

includelib  \masm32\lib\kernel32.lib
includelib  \masm32\lib\user32.lib

AutoType   PROTO :DWORD,:DWORD

.data

message     db  'HELLO MASM32 USER', 13, 10
            db  'THIS IS AN AUTOTYPING EXAMPLE', 0
app         db  'C:\windows\notepad.exe', 0

.data?

startinfo   STARTUPINFO         <?>
processinfo   PROCESS_INFORMATION   <?>

.code

start:

   Invoke WinExec, addr app, SW_SHOWNORMAL
   invoke   AutoType,eax,ADDR message
    invoke  ExitProcess, 0

AutoType   PROC USES esi hWnd:DWORD,_msg:DWORD

    mov     esi,_msg
@@:
    movzx   eax,BYTE PTR [esi]
    test    eax,eax
    jz      @f
    invoke keybd_event, eax, 0,0,0
    invoke  Sleep,100
    invoke keybd_event, eax, 0, KEYEVENTF_KEYUP, 0
    mov eax,0
   add      esi,1
    jmp     @b
@@:
   ret

AutoType   ENDP

END start