Code archives/Miscellaneous/automax.mod

This code has been declared by its author to be Public Domain code.

Download source code

automax.mod by plash2008
Updated 4/27/08 2:47PM EST

Contains functions for grabbing pixels from the screen, global hotkeys (can be detected outside of program), setting windows always on-top, pressing keys and mouse buttons/movements virtually.

Zip (v0.21): http://files.filefront.com/automax+v0+21zip/;10090541;/fileinfo.html
'It consists of multiple files, they will be posted in the
'comments or you can download them from the link above.

Comments

plash2008
Module interface is 'psh.mod\automax.mod\'.

automax.bmx


inc\getpixel.bmx


inc\GHotkey.bmx


inc\topmost.bmx


inc\VInput.bmx



TaskMaster2008
Any plans to make it cross platform?


plash2008
Examples:

Grabbing Pixels


Global Hotkeys


Virtual Input


Topmost window



plash2008
Any plans to make it cross platform?
I can play around with it on Linux once the other issues I'm having are resolved. I don't own a mac so no luck there, unless someone else wants to take a whack at it! :)


xlsior2008
Compile Error: Identifier 'GetDC' not found


??


xlsior2008
Hm... I couldn't get the module to compile unless I added the following to the automax.bmx file, per framework assistant's suggestion:


Import Pub.Win32


Then it compiled OK, but I am still unable to run your samples... for example, the hotkey sample gives me the following error when trying to run:

Unhandled Exception: Attempt to access field or method of Null object


I must be missing something, but your module + samples don't appear to work at all out of the box...


plash2008
Do it in debug, what line is causing the error?

I'll flip over to my winxp machine, remove the mod and try the code from this page.


plash2008
Yup, works fine here, copied code from page without any modifications. (bmax 1.28)


xlsior2008
OK, got it to work.

Turns out that there were two issues, when using the latest MaxGUI version.

1) It's missing the declaration of the win32 function GetDC().

I needed to either import Pub.win32 in automax.bmx, or add the following:
Extern "Win32"
	Function GetDC( hWnd )
End Extern


Looks like that one might have been linked by the older MaxGUI, but not any more. furthermore, the GUI code was generating an error in your sample:


"Unhandled Exception: Attempt to access field or methof of Null object"


on the following line:
Global Wnd_Main:TGadget = CreateWindow("", 75, 75, 260, 340, Desktop(), WINDOW_TITLEBAR)


That one went away after I changed the import line in the sample file to either one of these:

Import MaxGUI.Win32MaxGUI
or
Import MaxGUI.Win32MaxGUIex

instead of MaxGui.MaxGui

So... It seems to be working now, both in the latest MaxGUI SVN as with your original code in an older 1.28 backup copy of Blitzmax that I still had laying around.


so, I do have some other question and observation:

- Is it possible to capture any non-alphanumerical keys with your 'keylogger' routine? I don't really care about keyloggers per-se, but am interested in global shortcuts. Specifically, it it possible to see control/alt/shift modifiers, and things like the cursor keys?

I did notice that the 'keylogger' doesn't capture all keystrokes, and receives data out of order, especially if you type moderately fast. (Core 2 Duo, @2.4 Ghz)

For example:
"The Quick fox jumped over the lazy old dog" got logged as "HTEQCIUKFOXJUEMPDOEVHTLAZYLODDGO"


SebHoll2008
That one went away after I changed the import line in the sample file to either one of these:

Import MaxGUI.Win32MaxGUI
or
Import MaxGUI.Win32MaxGUIex

instead of MaxGui.MaxGui

Just thought I'd point out that for MaxGUI programs to compile with the new namespace, you need to Import at least one compatible driver for your platform.

MaxGUI.MaxGUI - this simply provides functions and a framework for the platform specific drivers to override and handle. Importing this by itself won't actually mean any gadget is created.

MaxGUI.Drivers - this is a new module which will selectively Import the platform's official MaxGUI driver. This should be the only Import you require to get MaxGUI working.

MaxGUI.Win32MaxGUI, MaxGUI.Win32MaxGUIEx, MaxGUI.CocoaMaxGUI, MaxGUI.FLTKMaxGUI - these are the official MaxGUI drivers that actually undertake the creation and handling of gadgets for the corresponding GUI framework. Although you can Import these directly, MaxGUI.Drivers does all this for you, so you should just use that.

I did notice that the 'keylogger' doesn't capture all keystrokes, and receives data out of order, especially if you type moderately fast. (Core 2 Duo, @2.4 Ghz)

"The Quick fox jumped over the lazy old dog" got logged as "HTEQCIUKFOXJUEMPDOEVHTLAZYLODDGO"

Try increasing the frequency of the timer to 20/50 Hz, e.g.

Local ticktime:TTimer = CreateTimer(4)
...to...

Local ticktime:TTimer = CreateTimer(20)
If you look at the way it outputs keystrokes, it should become clear why it is doing that. ;-)


plash2008
Honest mistake, I never used the newer maxgui module on my win32 machine.

It is possible to do global hotkeys - thats the reason I wrote it. You can create hotkeys using the THHotkey type and use, or write your own, CheckHotkeys() function.

The modi variables in the THHotkey type are for detecting key modifiers.

'modi1=Shift modi2=Ctrl modi3=Alt
Field modi1:Int, modi2:Int, modi3:Int


I will post an example using global hotkeys, include the fixes for maxgui.maxgui and make things more clear with THHotkey (ie. changing the modi vars to m_shift, m_ctrl, m_alt etc), including more object oriented and documented code. Soon.


plash2008
Done. See the examples post for a Global Hotkeys Example.

Changes:
Improved documentation 
Changed THHotkey type to TGHotkey, changed to be more OO 
Fixed module for newer maxgui 
Added extern 'GetDC' 



xlsior2008
Excellent!

Very nice.


SebHoll2008
Global hotkeys? Can you not just use SetHotKeyEvent()?


xlsior2008
Global hotkeys? Can you not just use SetHotKeyEvent()?


Plash's Global Hotkeys work when the blitz application does not have focus -- does SetHotKeyEvent() does that at well?
(This is one of those cases where the Blitz user manual could really, really use some more info and/or examples)


plash2008
There is another solution that will work over multiple virtual desktops, if you know my program dapp ( http://www.blitzbasic.com/Community/posts.php?topic=77865 ) that should make sense..

http://msdn.microsoft.com/en-us/library/ms646309.aspx

Its literally just a simple
RegisterHotKey(hWnd, _ID, MODKEY, KEY)


but it blocks any other application from using the same hotkey.


Code Archives Forum