Module interface is 'psh.mod\automax.mod\'.
automax.bmx
inc\getpixel.bmx
inc\GHotkey.bmx
inc\topmost.bmx
inc\VInput.bmx
automax.bmx
SuperStrict Import BRL.linkedlist Import maxgui.Win32MaxGui 'users of the old maxgui can recompile the mod with BRL.Win32MaxGui Rem bbdoc: AutoMax about: Extended Win32 (only) features module End Rem Module psh.automax ModuleInfo "Version: 0.21" ModuleInfo "Author: Tim Howard" ModuleInfo "History: v0.21" ModuleInfo "History: Improved documentation" ModuleInfo "History: Changed THHotkey type to TGHotkey, changed to be more OO" ModuleInfo "History: Fixed module for newer maxgui" ModuleInfo "History: Added extern 'GetDC'" ModuleInfo "History: v0.1" ModuleInfo "History: Initial release, basic functionality" Include "inc\VInput.bmx" Include "inc\GHotkey.bmx" Include "inc\topmost.bmx" Include "inc\getpixel.bmx"
inc\getpixel.bmx
Extern "Win32" Function apiGetPixel:Int(hdc:Int, X:Int, Y:Int) = "GetPixel@12" Function GetDC:Int(hWnd:Int) End Extern Private Global HDC_DESKTOP:Int = GetDC(0) Rem example Local p:Int = dGetPixel(931, 709), r:Int, g:Int, b:Int ApiRGB(p, r, g, b) DebugLog p + "|" + r + ", " + g + ", " + b p = PrepRGB(r, g, b) DebugLog p + "|" + r + ", " + g + ", " + b EndRem Public Rem bbdoc: GetPixel Function about: Gets the color of a pixel on the screen. returns: A single integer value containing R, G and B color values. See #ApiRGB EndRem Function GetPixel:Int(X:Int, Y:Int) Return apiGetPixel(HDC_DESKTOP, X, Y) End Function Rem 'Removed silly function Function CompareColors:Int(Col1:Int, Col2:Int) If Col1 = Col2 Then Return 1 Else Return 0 End Function EndRem Rem bbdoc: PrepRGB Function about: Creates an APIRGB color variable and returns it. returns: A single integer value containing R, G and B color values. See #ApiRGB EndRem Function PrepRGB:Int(Red:Int, Green:Int, Blue:Int) Return (RED | GREEN Shl 8 | BLUE Shl 16) End Function Rem bbdoc: ApiRGB Function about: Takes in a single integer value, and sets individual RGB variables (from functions #PrepRGB and #GetPixel) returns: Nothing, sets values Red, Green and Blue EndRem Function ApiRGB(Pixel:Int, Red:Int Var, Green:Int Var, Blue:Int Var) Red = (Pixel Shr 0) & 255 Green = (Pixel Shr 8) & 255 Blue = (Pixel Shr 16) & 255 End Function
inc\GHotkey.bmx
Extern "Win32" Function GetAsyncKeyState:Int(vKey:Int) EndExtern Rem bbdoc: TGHotkey Type End Rem Type TGHotkey Global _list:TList = New TList Rem bbdoc: Shift modifier End Rem Field m_shift:Int Rem bbdoc: Ctrl modifier End Rem Field m_ctrl:Int Rem bbdoc: Alt modifier End Rem Field m_alt:Int Rem bbdoc: Key to be checked End Rem Field key:Int Rem bbdoc: Internal End Rem Field khit:Int Rem bbdoc: Function to be called when hotkey (& modifiers) pressed End Rem Field _callback(Obj:TGHotkey) Method New() _list.AddLast(Self) End Method Method remove() _list.remove(Self) End Method Rem bbdoc: CheckHotkeys Function about: Checks all global hotkeys, if key pressed executes callback function End Rem Function CheckHotkeys() Local th:TGHotkey For th = EachIn TGHotkey._list Local GKD_CTRL:Int = GKeyDown(VK_CONTROL) Local GKD_MENU:Int = GKeyDown(VK_MENU) Local GKD_SHIFT:Int = GKeyDown(VK_SHIFT) Local totkeys:Int = 1 totkeys:+th.m_shift + th.m_ctrl + th.m_alt Local Keys:Int = GKeyDown(th.key) If th.m_shift = 1 Then Keys:+GKD_SHIFT If th.m_ctrl = 1 Then Keys:+GKD_CTRL If th.m_alt = 1 Then Keys:+GKD_MENU 'DebugLog keys If keys = totkeys 'DebugLog keys + ", " + th.khit If th.khit = 0 th.khit = 1 th._callback(th) EndIf Else th.khit = 0 EndIf Next End Function Rem bbdoc: CreateHotkey Function- Internal, see #CreateGlobalHotkey about: @m_shift @m_ctrl and @m_alt are boolean variables to specify the modifiers for the key, @key is any KEY_ variable. returns: The new hotkey End Rem Function Create:TGHotkey(key:Int, m_shift:Int, m_ctrl:Int, m_alt:Int, callback(Obj:TGHotkey)) Local th:TGHotkey = New TGHotkey th.key = key th.m_shift = m_shift th.m_ctrl = m_ctrl th.m_alt = m_alt th._callback = callback Return th End Function End Type Rem bbdoc: CreateGlobalHotkey Function about: @m_shift @m_ctrl and @m_alt are boolean variables to specify the modifiers for the key returns: The new hotkey End Rem Function CreateGlobalHotkey:TGHotkey(key:Int, m_shift:Int, m_ctrl:Int, m_alt:Int, callback(Obj:TGHotkey)) Return TGHotkey.Create(key, m_shift, m_ctrl, m_alt, callback) End Function Rem bbdoc: GKeyDown Function returns: The state of the virtual key sent to the function. End Rem Function GKeyDown:Int(VirtualKey:Int) 'If (IgnoreFocus = True) And (GetActiveWindow() = 0) Then Return Return (GetAsyncKeyState:Int(VirtualKey) And %1000000000000000) > 0 End Function
inc\topmost.bmx
Extern "win32" Function SetWindowPos:Int(hWnd:Int, hAfter:Int, X:Int, Y:Int, cx:Int, cy:Int, flags:Int) End Extern Private Global HWND_TOPMOST:Int = -1 Rem example Wnd_Main:TGadget = CreateWindow("A WINDOW", 0, 0, 800, 600, Desktop(), WINDOW_TOOL) SetWindowPos QueryGadget(Wnd_Main, QUERY_HWND), HWND_TOPMOST, 0, 0, 800, 600, 0 End Rem Public Rem bbdoc: SetWindowTopMost Function about: Sets the window to always on top. returns: nothing EndRem Function SetWindowTopMost(Gadget:TGadget) SetWindowPos QueryGadget(Gadget, QUERY_HWND), HWND_TOPMOST, GadgetX(Gadget), GadgetY(Gadget), GadgetWidth(Gadget), GadgetHeight(Gadget), 0 End Function
inc\VInput.bmx
'SuperStrict '#Region Mouse Variables Const MOUSEEVENTF_ABSOLUTE:Int = -32768 ' // Use absolute coords Const MOUSEEVENTF_MOVE:Int = 1 ' // Trigger move event Const MOUSEEVENTF_LEFTDOWN:Int = 2 ' // LMB Down Const MOUSEEVENTF_LEFTUP:Int = 4 ' // LMB Up Const MOUSEEVENTF_RIGHTDOWN:Int = 8 ' // RMB Down Const MOUSEEVENTF_RIGHTUP:Int = 16 ' // RMB Up Const MOUSEEVENTF_MIDDLEDOWN:Int = 32 ' // MMB Down Const MOUSEEVENTF_MIDDLEUP:Int = 64 ' // MMB Up Const MOUSEEVENTF_WHEEL:Int = 128 ' // NT Only: Mouse wheel moved '#End Region '#Region Virtual Keys Const VK_ADD:Byte = $6B Const VK_ATTN:Byte = $F6 Const VK_BACK:Byte = $8 Const VK_CANCEL:Byte = $3 Const VK_CAPITAL:Byte = $14 Const VK_CLEAR:Byte = $C Const VK_CONTROL_:Byte = $11 Const VK_CRSEL:Byte = $F7 Const VK_DECIMAL:Byte = $6E Const VK_DELETE:Byte = $2E Const VK_DIVIDE:Byte = $6F Const VK_DOWN:Byte = $28 Const VK_END:Byte = $23 Const VK_EREOF:Byte = $F9 Const VK_ESCAPE:Byte = $1B Const VK_EXECUTE:Byte = $2B Const VK_EXSEL:Byte = $F8 Const VK_HELP:Byte = $2F Const VK_HOME:Byte = $24 Const VK_INSERT:Byte = $2D Const VK_LBUTTON:Byte = $1 Const VK_LCONTROL:Byte = $A2 Const VK_LEFT:Byte = $25 Const VK_LMENU:Byte = $A4 Const VK_LSHIFT:Byte = $A0 Const VK_MBUTTON:Byte = $4 Const VK_MENU:Byte = $12 Const VK_MULTIPLY:Byte = $6A Const VK_NEXT:Byte = $22 Const VK_NONAME:Byte = $FC Const VK_NUMLOCK:Byte = $90 Const VK_NUMPAD0:Byte = $60 Const VK_NUMPAD1:Byte = $61 Const VK_NUMPAD2:Byte = $62 Const VK_NUMPAD3:Byte = $63 Const VK_NUMPAD4:Byte = $64 Const VK_NUMPAD5:Byte = $65 Const VK_NUMPAD6:Byte = $66 Const VK_NUMPAD7:Byte = $67 Const VK_NUMPAD8:Byte = $68 Const VK_NUMPAD9:Byte = $69 Const VK_OEM_CLEAR:Byte = $FE Const VK_PA1:Byte = $FD Const VK_PAUSE:Byte = $13 Const VK_PLAY:Byte = $FA Const VK_PRINT:Byte = $2A Const VK_PRIOR:Byte = $21 Const VK_PROCESSKEY:Byte = $E5 Const VK_RBUTTON:Byte = $2 Const VK_RCONTROL:Byte = $A3 Const VK_RETURN:Byte = $D Const VK_RIGHT:Byte = $27 Const VK_RMENU:Byte = $A5 Const VK_RSHIFT:Byte = $A1 Const VK_SCROLL:Byte = $91 Const VK_SELECT:Byte = $29 Const VK_SEPARATOR:Byte = $6C Const VK_SHIFT:Byte = $10 Const VK_SNAPSHOT:Byte = $2C Const VK_SPACE:Byte = $20 Const VK_SUBTRACT:Byte = $6D Const VK_TAB:Byte = $9 Const VK_UP:Byte = $26 Const VK_ZOOM:Byte = $FB 'Const KEYEVENTF_KEYUP:Byte = $00000002 '#End Region Extern "win32" Function GetCursorPos(Point:Byte Ptr) Function SetCursorPos(x:Int, y:Int) Function keybd_event(bVk:Byte, bScan:Byte, dwFlags:Byte, dwExtraInfo:Int) Function mouse_event(dwFlags:Int, dx:Int, dy:Int, cButtons:Int, dwExtraInfo:Int) End Extern Rem MouseAction MOUSEEVENTF_LEFTDOWN + MOUSEEVENTF_LEFTUP, 0, 0, 0 MouseAction MOUSEEVENTF_LEFTDOWN + MOUSEEVENTF_LEFTUP, 17, 702, 1 Delay 5000 MouseAction MOUSEEVENTF_LEFTDOWN + MOUSEEVENTF_LEFTUP, 17, 702, 2 EndRem Rem 'system_ "notepad.exe" Delay 2000 FKeyStroke Key_A FKeyStroke Key_B', 2000 SKeyStroke Key_C, 1 Delay 5000 SKeyStroke Key_C, 2 EndRem 'Example: MouseAction MOUSEEVENTF_LEFTDOWN + MOUSEEVENTF_LEFTUP, 0, 0 Rem bbdoc: Sends a mouse click to the computer. about: @Flags can be any MOUSEEVENTF_ values or a combination (ie, MOUSEEVENTF_LEFTDOWN + MOUSEEVENTF_LEFTUP) @X position to send mouse to @Y position to send mouse to @mm is a choice variable, 0=do not move mouse, 1=move mouse 2=move mouse, click, then return to previouse mouse position returns: nothing EndRem Function MouseAction(Flags:Int, X:Int, Y:Int, mm:Int = 1) Select mm Case 0 mouse_event Flags:Int, 0, 0, 0, 0 Case 1 SetCursorPos X, Y mouse_event Flags:Int, 0, 0, 0, 0 Case 2 Local Point:Int[2] GetCursorPos Point ; SetCursorPos X, Y mouse_event Flags:Int, 0, 0, 0, 0 SetCursorPos Point[0], Point[1] End Select End Function 'Example: KeyStroke KEY_A Rem bbdoc: Sends a full keystroke to the computer. about: @VK_KEYV key to be pressed, can be any VK_ variable returns: nothing EndRem Function FKeyStroke(VK_KEYV:Byte) keybd_event(VK_KEYV, 0, 0, 0) 'Delay dly keybd_event(VK_KEYV, 0, 2, 0) End Function 'Example: KeyStroke KEY_A, 0 ; KeyStroke KEY_A, 2 Rem bbdoc: Sends a single keystroke to the computer. about: @VK_KEYV: key to be pressed, can be any VK_ variable @updn: 1=down 2=up returns: nothing EndRem Function SKeyStroke(VK_KEYV:Byte, updn:Byte = 0) keybd_event(VK_KEYV, 0, updn, 0) End Function