AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

WinEventHook example...
Goto page Previous  1, 2, 3, 4, 5, 6  Next
 
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Scripts & Functions
View previous topic :: View next topic  
Author Message
majkinetor



Joined: 24 May 2006
Posts: 3592
Location: Belgrade

PostPosted: Wed May 23, 2007 9:15 am    Post subject: Reply with quote

JGR, do you have some ideas, can you catch Restore/Maximize event with WinEvents hook ?
_________________
Back to top
View user's profile Send private message MSN Messenger
JGR



Joined: 15 Jun 2006
Posts: 52
Location: Unavailable until ~30th August

PostPosted: Wed May 23, 2007 9:44 am    Post subject: Reply with quote

Yes, and window movement as well Surprised
http://www.autohotkey.com/forum/viewtopic.php?p=123574#123574
http://www.autohotkey.com/forum/viewtopic.php?p=123572#123572


JGR
Back to top
View user's profile Send private message
Sean



Joined: 12 Feb 2007
Posts: 1247

PostPosted: Wed May 23, 2007 10:27 am    Post subject: Reply with quote

JGR wrote:
I have done the same thing to callback.dll and reuploaded the archive...
It is now 1024 bytes, and does not import ExitProcess, I could not determine whether this works any better in my five minutes of testing it, but it is only really going to be loaded into autohotkey's process anyway.

Thanks. Now the LoadLibrary symptom with callback.dll is also gone now.
BTW, it amazed me to see the module size can be as small as 1KB.
As far as I'm aware, this is the smallest module size I've ever seen.
How much further can it be reduced?
Back to top
View user's profile Send private message
JGR



Joined: 15 Jun 2006
Posts: 52
Location: Unavailable until ~30th August

PostPosted: Wed May 23, 2007 10:31 am    Post subject: Reply with quote

Beyond a certain limit (a bit less than what I've got now), PE compaction goes all esoteric and is a bit dodgy, using table pointers to hold code, partially invalid headers, 1 byte file alignment, hard coded api function points, no relocation data...
The thing is that many of these don't work on DLLs.

I've seen one PE EXE that was 330 bytes... It didn't do very much though...
Back to top
View user's profile Send private message
Sean



Joined: 12 Feb 2007
Posts: 1247

PostPosted: Wed May 23, 2007 10:56 am    Post subject: Reply with quote

JGR wrote:
I've seen one PE EXE that was 330 bytes... It didn't do very much though...

I just found this page where the conclusion is:

Code:
* Smallest possible PE file: 97 bytes
* Smallest possible PE file on Windows 2000: 133 bytes
* Smallest PE file that downloads a file over WebDAV and executes it: 133 bytes
Back to top
View user's profile Send private message
Laszlo



Joined: 14 Feb 2005
Posts: 3942
Location: Pittsburgh

PostPosted: Fri Jun 01, 2007 11:35 pm    Post subject: Reply with quote

JGR: From the example it looks like that only system events, like EVENT_SYSTEM_FOREGROUND, console events, like EVENT_CONSOLE_CARET and object events, like EVENT_OBJECT_CREATE can be hooked with this dll. I am in desperate need of a keyboard hook.

MSDN indicates, that it can be done with SetWindowsHookEx, with the WH_KEYBOARD Hook, specifying a KeyboardProc callback Function. Can it be done with the posted wineventhook.dll? If yes, how? If not, is it hard to modify the dll for this, and do you plan to do it?
Back to top
View user's profile Send private message
Sean



Joined: 12 Feb 2007
Posts: 1247

PostPosted: Fri Jun 01, 2007 11:55 pm    Post subject: Reply with quote

Laszlo wrote:
MSDN indicates, that it can be done with SetWindowsHookEx, with the WH_KEYBOARD Hook, specifying a KeyboardProc callback Function.

I'm not JGR, but it's possible using ahkhook.dll:
http://www.autohotkey.net/~JGR/cbthook.rar
Back to top
View user's profile Send private message
Laszlo



Joined: 14 Feb 2005
Posts: 3942
Location: Pittsburgh

PostPosted: Sat Jun 02, 2007 12:08 am    Post subject: Reply with quote

Thanks, Sean, for the link. If you know that dll, could you tell how to use it? I could not even figure out what the parameters are. I tried the example (hook.ahk), and it reacts extremely slowly in my machine, makes the taskbar transparent and eventually crashes the PC. I don't know, if it is a strange interaction with one of the many applications running in my PC, having no clue what the hook does.
Back to top
View user's profile Send private message
Sean



Joined: 12 Feb 2007
Posts: 1247

PostPosted: Sat Jun 02, 2007 12:38 am    Post subject: Reply with quote

Laszlo wrote:
Thanks, Sean, for the link. If you know that dll, could you tell how to use it? I could not even figure out what the parameters are. I tried the example (hook.ahk), and it reacts extremely slowly in my machine, makes the taskbar transparent and eventually crashes the PC. I don't know, if it is a strange interaction with one of the many applications running in my PC, having no clue what the hook does.

I just wrote it for the keybdhook. It seems to work in quick test here.

Code:
WH_KEYBOARD := 2
WH_CBT      := 5
WH_MOUSE    := 7

HC_ACTION   := 0
HC_NOREMOVE := 3

DetectHiddenWindows, On
Process, Exist
hAHK := WinExist("ahk_pid " . ErrorLevel)

WM_AHK_Callback := DllCall("RegisterWindowMessage", "str", "WM_AHK_Callback")
OnMessage(WM_AHK_Callback + HC_ACTION  , "KeybdHook")
OnMessage(WM_AHK_Callback + HC_NOREMOVE, "KeybdHook")

DllCall("LoadLibrary", "str", "ahkhook.dll")
hHook := DllCall("ahkhook\reghook", "Uint", WH_KEYBOARD, "Uint", hAHK, "Uint", WM_AHK_Callback, "Uint", 1<<HC_ACTION|1<<HC_NOREMOVE)

#End::
DllCall("UnhookWindowsHookEx", "Uint", hHook)
DllCall("FreeLibrary", "Uint", DllCall("GetModuleHandle", "str", "ahkhook.dll"))
ExitApp

KeybdHook(wParam, lParam, nMsg)
{
   Critical
   Global WM_AHK_Callback
   OutputDebug, % wParam . "|" . lParam . "|" . nMsg - WM_AHK_Callback
   Return 0
}
Back to top
View user's profile Send private message
Laszlo



Joined: 14 Feb 2005
Posts: 3942
Location: Pittsburgh

PostPosted: Sat Jun 02, 2007 12:49 am    Post subject: Reply with quote

This works! Thanks!
Back to top
View user's profile Send private message
Sean



Joined: 12 Feb 2007
Posts: 1247

PostPosted: Mon Jun 11, 2007 4:19 am    Post subject: Reply with quote

Hi Laszlo,

This script can be an alternative to the previous one, utilizing AHK's built-in RegisterCallback:

Code:
#Persistent
OnExit, Unhook

hHookKeybd := SetWindowsHookEx(WH_KEYBOARD_LL   := 13, RegisterCallback("Keyboard", "Fast"))
;hHookMouse := SetWindowsHookEx(WH_MOUSE_LL   := 14, RegisterCallback("MouseMove", "Fast"))
Return

Unhook:
UnhookWindowsHookEx(hHookKeybd)
;UnhookWindowsHookEx(hHookMouse)
ExitApp


Keyboard(nCode, wParam, lParam)
{
   Critical
   If !nCode
   OutputDebug, % wParam . "|" . " vkCode: " . NumGet(lParam+0, 0) . " scCode: " . NumGet(lParam+0, 4) . " Extended: " . NumGet(lParam+0, 8) & 1 . " Time: " . NumGet(lParam+0, 12)
   Return CallNextHookEx(nCode, wParam, lParam)
}

MouseMove(nCode, wParam, lParam)
{
   Critical
   If !nCode && (wParam = 0x200)
   OutputDebug, % " X: " . NumGet(lParam+0, 0, "int") . " Y: " . NumGet(lParam+0, 4, "int")
   Return CallNextHookEx(nCode, wParam, lParam)
}

SetWindowsHookEx(idHook, pfn)
{
   Return DllCall("SetWindowsHookEx", "int", idHook, "Uint", pfn, "Uint", DllCall("GetModuleHandle", "Uint", 0), "Uint", 0)
}

UnhookWindowsHookEx(hHook)
{
   Return DllCall("UnhookWindowsHookEx", "Uint", hHook)
}

CallNextHookEx(nCode, wParam, lParam, hHook = 0)
{
   Return DllCall("CallNextHookEx", "Uint", hHook, "int", nCode, "Uint", wParam, "Uint", lParam)
}
Back to top
View user's profile Send private message
Laszlo



Joined: 14 Feb 2005
Posts: 3942
Location: Pittsburgh

PostPosted: Mon Jun 11, 2007 6:05 am    Post subject: Reply with quote

Thanks! It works equally well, does not need the external dll and the script is shorter. What more can we desire?
Back to top
View user's profile Send private message
Slaya
Guest





PostPosted: Thu Jul 19, 2007 9:51 pm    Post subject: Help needed Reply with quote

To all who know something about hooking, please have a look
at this topic in the help section.

http://www.autohotkey.com/forum/topic21315.html

Thanks

~Slaya
Back to top
Sean



Joined: 12 Feb 2007
Posts: 1247

PostPosted: Fri Jul 20, 2007 3:09 am    Post subject: Re: Help needed Reply with quote

Slaya wrote:
To all who know something about hooking, please have a look at this topic in the help section.
http://www.autohotkey.com/forum/topic21315.html

No, ahkhook.dll via OnMessage is not appropriate to use here as need to access the memory space of the other processes frequently, although it's not entirely impossible.
Back to top
View user's profile Send private message
Mustang



Joined: 17 May 2007
Posts: 362
Location: England

PostPosted: Thu Jan 03, 2008 10:52 pm    Post subject: Reply with quote

Sean wrote:
Hi Laszlo,

This script can be an alternative to the previous one, utilizing AHK's built-in RegisterCallback:

Code:
#Persistent
OnExit, Unhook

hHookKeybd := SetWindowsHookEx(WH_KEYBOARD_LL   := 13, RegisterCallback("Keyboard", "Fast"))
;hHookMouse := SetWindowsHookEx(WH_MOUSE_LL   := 14, RegisterCallback("MouseMove", "Fast"))
Return

Unhook:
UnhookWindowsHookEx(hHookKeybd)
;UnhookWindowsHookEx(hHookMouse)
ExitApp


Keyboard(nCode, wParam, lParam)
{
   Critical
   If !nCode
   OutputDebug, % wParam . "|" . " vkCode: " . NumGet(lParam+0, 0) . " scCode: " . NumGet(lParam+0, 4) . " Extended: " . NumGet(lParam+0, 8) & 1 . " Time: " . NumGet(lParam+0, 12)
   Return CallNextHookEx(nCode, wParam, lParam)
}

MouseMove(nCode, wParam, lParam)
{
   Critical
   If !nCode && (wParam = 0x200)
   OutputDebug, % " X: " . NumGet(lParam+0, 0, "int") . " Y: " . NumGet(lParam+0, 4, "int")
   Return CallNextHookEx(nCode, wParam, lParam)
}

SetWindowsHookEx(idHook, pfn)
{
   Return DllCall("SetWindowsHookEx", "int", idHook, "Uint", pfn, "Uint", DllCall("GetModuleHandle", "Uint", 0), "Uint", 0)
}

UnhookWindowsHookEx(hHook)
{
   Return DllCall("UnhookWindowsHookEx", "Uint", hHook)
}

CallNextHookEx(nCode, wParam, lParam, hHook = 0)
{
   Return DllCall("CallNextHookEx", "Uint", hHook, "int", nCode, "Uint", wParam, "Uint", lParam)
}

I'm trying to modify this to work with WH_CALLWNDPROC and WH_SHELL
But can't get it to work for me on Vista Sad
Here is the code I used:
Code:
OnExit, Unhook

hHookWindow := SetWindowsHookEx( (WH_CALLWNDPROC:=0x04), RegisterCallback("Window", "Fast"))
Return

Unhook:
UnhookWindowsHookEx(hHookWindow)
ExitApp

Window(nCode, wParam, lParam)
{
    ToolTip, %nCode% %wParam% %lParam%
    Return, CallNextHookEx(nCode, wParam, lParam)
}

SetWindowsHookEx(idHook, pfn)
{
   Return DllCall("SetWindowsHookEx", "int", idHook, "Uint", pfn, "Uint", DllCall("GetModuleHandle", "Uint", 0), "Uint", 0)
}

UnhookWindowsHookEx(hHook)
{
   Return DllCall("UnhookWindowsHookEx", "Uint", hHook)
}

CallNextHookEx(nCode, wParam, lParam, hHook = 0)
{
   Return DllCall("CallNextHookEx", "UInt", hHook, "Int", nCode, "Uint", wParam, "Uint", lParam)
}
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Scripts & Functions All times are GMT
Goto page Previous  1, 2, 3, 4, 5, 6  Next
Page 4 of 6

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group