Search the Community
Showing results for tags 'hooking'.
-
Harro, I am trying to poll Skype for events, I want something to happen when it is minimised. I have found some code on the forum that almost works, I have been tweaking it, but just can't get the minimise event to work. I would love some help on this. as I am not amamzing at DLL calling and such... the event handle for $EVENT_SYSTEM_MINIMIZEEND is never hit.. even when i minimise the window, i always get the same event codes. Here is what I have so far... #include <WindowsConstants.au3> #include <WinAPI.au3> #include <Process.au3> #include <Misc.au3> Global $hDLL, $hWinEventProc, $hHook HotKeySet("{ESC}", "_HotKey") ; Exit ;Event Constants Global Const $EVENT_SYSTEM_SOUND = 0x0001 ;An MSAA event indicating that a sound was played. Global Const $EVENT_SYSTEM_ALERT = 0x0002 ;An MSAA event indicating that an alert was generated. Global Const $EVENT_SYSTEM_FOREGROUND = 0x0003 ;An MSAA event indicating that the foreground window changed. Global Const $EVENT_SYSTEM_MENUSTART = 0x0004 ;An MSAA event indicating that a menu item on the menu bar was selected. Global Const $EVENT_SYSTEM_MENUEND = 0x0005 ;An MSAA event indicating that a menu from the menu bar was closed. Global Const $EVENT_SYSTEM_MENUPOPUPSTART = 0x0006 ;An MSAA event indicating that a pop-up menu was displayed. Global Const $EVENT_SYSTEM_MENUPOPUPEND = 0x0007 ;An MSAA event indicating that a pop-up menu was closed. Global Const $EVENT_SYSTEM_CAPTURESTART = 0x0008 ;An MSAA event indicating that a window has received mouse capture. Global Const $EVENT_SYSTEM_CAPTUREEND = 0x0009 ;An MSAA event indicating that a window has lost mouse capture. Global Const $EVENT_SYSTEM_DIALOGSTART = 0x0010 ;An MSAA event indicating that a dialog box was displayed. Global Const $EVENT_SYSTEM_DIALOGEND = 0x0011 ;An MSAA event indicating that a dialog box was closed. Global Const $EVENT_SYSTEM_SCROLLINGSTART = 0x0012 ;An MSAA event indicating that scrolling has started on a scroll bar. Global Const $EVENT_SYSTEM_SCROLLINGEND = 0x0013 ;An MSAA event indicating that scrolling has ended on a scroll bar. Global Const $EVENT_SYSTEM_SWITCHSTART = 0x0014 ;An MSAA event indicating that the user pressed ALT+TAB, which activates the switch window. Global Const $EVENT_SYSTEM_SWITCHEND = 0x0015 ;An MSAA event indicating that the user released ALT+TAB. Global Const $EVENT_SYSTEM_MINIMIZESTART = 0x0016 ;An MSAA event indicating that a window object is about to be minimized or maximized. Global Const $EVENT_SYSTEM_MINIMIZEEND = 0x0017 ;An MSAA event indicating that a window object was minimized or maximized. Global Const $EVENT_SYSTEM_MOVESIZESTART = 0x000A ;An MSAA event indicating that a window is being moved or resized. Global Const $EVENT_SYSTEM_MOVESIZEEND = 0x000B ;An MSAA event indicating that the movement or resizing of a window is finished. Global Const $EVENT_SYSTEM_CONTEXTHELPSTART = 0x000C ;An MSAA event indicating that a window entered context-sensitive Help mode. Global Const $EVENT_SYSTEM_CONTEXTHELPEND = 0x000D ;An MSAA event indicating that a window exited context-sensitive Help mode. Global Const $EVENT_SYSTEM_DRAGDROPSTART = 0x000E ;An MSAA event indicating that an application is about to enter drag-and-drop mode. Global Const $EVENT_SYSTEM_DRAGDROPEND = 0x000F ;An MSAA event indicating that an application is about to exit drag-and-drop mode. Global Const $EVENT_OBJECT_CREATE = 0x8000 ;An MSAA event indicating that an object was created. Global Const $EVENT_OBJECT_DESTROY = 0x8001 ;An MSAA event indicating that an object was destroyed. Global Const $EVENT_OBJECT_SHOW = 0x8002 ;An MSAA event indicating that a hidden object is being shown. Global Const $EVENT_OBJECT_HIDE = 0x8003 ;An MSAA event indicating that an object is being hidden. Global Const $EVENT_OBJECT_REORDER = 0x8004 ;An MSAA event indicating that a container object has added, removed, or reordered its children. Global Const $EVENT_OBJECT_FOCUS = 0x8005 ;An MSAA event indicating that an object has received the keyboard focus. Global Const $EVENT_OBJECT_SELECTION = 0x8006 ;An MSAA event indicating that the selection within a container object changed. Global Const $EVENT_OBJECT_SELECTIONADD = 0x8007 ;An MSAA event indicating that an item within a container object was added to the selection. Global Const $EVENT_OBJECT_SELECTIONREMOVE = 0x8008 ;An MSAA event indicating that an item within a container object was removed from the selection. Global Const $EVENT_OBJECT_SELECTIONWITHIN = 0x8009 ;An MSAA event indicating that numerous selection changes occurred within a container object. Global Const $EVENT_OBJECT_HELPCHANGE = 0x8010 ;An MSAA event indicating that an object's MSAA Help property changed. Global Const $EVENT_OBJECT_DEFACTIonchange = 0x8011 ;An MSAA event indicating that an object's MSAA DefaultAction property changed. Global Const $EVENT_OBJECT_ACCELERATORCHANGE = 0x8012 ;An MSAA event indicating that an object's MSAA KeyboardShortcut property changed. Global Const $EVENT_OBJECT_INVOKED = 0x8013 ;An MSAA event indicating that an object has been invoked; for example, the user has clicked a button. Global Const $EVENT_OBJECT_TEXTSELECTIonchangeD = 0x8014 ;An MSAA event indicating that an object's text selection has changed. Global Const $EVENT_OBJECT_CONTENTSCROLLED = 0x8015 ;An MSAA event indicating that the scrolling of a window object has ended. Global Const $EVENT_OBJECT_STATECHANGE = 0x800A ;An MSAA event indicating that an object's state has changed. Global Const $EVENT_OBJECT_LOCATIonchange = 0x800B ;An MSAA event indicating that an object has changed location, shape, or size. Global Const $EVENT_OBJECT_NAMECHANGE = 0x800C ;An MSAA event indicating that an object's MSAA Name property changed. Global Const $EVENT_OBJECT_DESCRIPTIonchange = 0x800D ;An MSAA event indicating that an object's MSAA Description property changed. Global Const $EVENT_OBJECT_VALUECHANGE = 0x800E ;An MSAA event indicating that an object's MSAA Value property changed. Global Const $EVENT_OBJECT_PARENTCHANGE = 0x800F ;An MSAA event indicating that an object has a new parent object. ;minimum and maximum events ;to monitor one event type only use same event for min/max Global $EVENT_Min = $EVENT_SYSTEM_SOUND Global $EVENT_Max = $EVENT_SYSTEM_DRAGDROPEND $hDLL = DllOpen("User32.dll") $hWinEventProc = DllCallbackRegister("_WinEventProc", "none", "hwnd;int;hwnd;long;long;int;int") If Not @error Then OnAutoItExitRegister("OnAutoItExit") Else MsgBox(16 + 262144, "Error", "DllCallbackRegister(_WinEventProc) did not succeed.") Exit EndIf $hHook = _SetWinEventHook($EVENT_Min, $EVENT_Max, $hDLL) If @error Then MsgBox(16 + 262144, "Error", "_SetWinEventHook() did not succeed.") Exit EndIf While 1 Sleep(10) WEnd Func _WinEventProc($hHook, $iEvent, $hWnd, $idObject, $idChild, $iEventThread, $iEventTime) Local $PID = WinGetProcess($hWnd), $sEventProcName = _ProcessGetName($PID) ConsoleWrite("PID: " & $PID & @TAB & "WinTitle: " & StringLeft(WinGetTitle($hWnd), 30) & @TAB & "EventTime: " & $iEventTime & @TAB & @TAB & "Event: " & $iEvent & @CRLF) ConsoleWrite($idObject) if((StringInStr(WinGetTitle($hWnd),"Skype"))>=1) Then if($iEvent = $EVENT_SYSTEM_MINIMIZEEND) Then ConsoleWrite("Skype has been minimised!!") EndIf EndIf EndFunc ;==>_WinEventProc Func _SetWinEventHook($iEventMin, $iEventMax, $hDLLUser32) Local $aRet Local Const $WINEVENT_OUTOFCONTEXT = 0x0 Local Const $WINEVENT_SKIPOWNPROCESS = 0x2 If Not $hDLLUser32 Or $hDLLUser32 = -1 Then $hDLLUser32 = "User32.dll" $aRet = DllCall($hDLLUser32, "hwnd", "SetWinEventHook", _ "uint", $iEventMin, _ "uint", $iEventMax, _ "hwnd", 0, _ "ptr", DllCallbackGetPtr($hWinEventProc), _ "int", 0, _ "int", 0, _ "uint", BitOR($WINEVENT_OUTOFCONTEXT, $WINEVENT_SKIPOWNPROCESS)) If @error Then Return SetError(@error, 0, 0) Return $aRet[0] EndFunc ;==>_SetWinEventHook Func _HotKey() Switch @HotKeyPressed Case "{ESC}" Exit EndSwitch EndFunc ;==>_HotKey Func OnAutoItExit() If $hWinEventProc Then Beep(3000, 5) DllCallbackFree($hWinEventProc) EndIf If $hHook Then DllCall("User32.dll", "int", "UnhookWinEvent", "hwnd", $hHook) If $hDLL Then DllClose($hDLL) EndFunc ;==>OnAutoItExit