 |
AutoHotkey Community Let's help each other out
|
| View previous topic :: View next topic |
| Author |
Message |
majkinetor
Joined: 24 May 2006 Posts: 3592 Location: Belgrade
|
Posted: Wed May 23, 2007 9:15 am Post subject: |
|
|
JGR, do you have some ideas, can you catch Restore/Maximize event with WinEvents hook ? _________________
 |
|
| Back to top |
|
 |
JGR
Joined: 15 Jun 2006 Posts: 52 Location: Unavailable until ~30th August
|
|
| Back to top |
|
 |
Sean
Joined: 12 Feb 2007 Posts: 1247
|
Posted: Wed May 23, 2007 10:27 am Post subject: |
|
|
| 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 |
|
 |
JGR
Joined: 15 Jun 2006 Posts: 52 Location: Unavailable until ~30th August
|
Posted: Wed May 23, 2007 10:31 am Post subject: |
|
|
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 |
|
 |
Sean
Joined: 12 Feb 2007 Posts: 1247
|
Posted: Wed May 23, 2007 10:56 am Post subject: |
|
|
| 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 |
|
 |
Laszlo
Joined: 14 Feb 2005 Posts: 3942 Location: Pittsburgh
|
Posted: Fri Jun 01, 2007 11:35 pm Post subject: |
|
|
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 |
|
 |
Sean
Joined: 12 Feb 2007 Posts: 1247
|
Posted: Fri Jun 01, 2007 11:55 pm Post subject: |
|
|
| 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 |
|
 |
Laszlo
Joined: 14 Feb 2005 Posts: 3942 Location: Pittsburgh
|
Posted: Sat Jun 02, 2007 12:08 am Post subject: |
|
|
| 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 |
|
 |
Sean
Joined: 12 Feb 2007 Posts: 1247
|
Posted: Sat Jun 02, 2007 12:38 am Post subject: |
|
|
| 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 |
|
 |
Laszlo
Joined: 14 Feb 2005 Posts: 3942 Location: Pittsburgh
|
Posted: Sat Jun 02, 2007 12:49 am Post subject: |
|
|
| This works! Thanks! |
|
| Back to top |
|
 |
Sean
Joined: 12 Feb 2007 Posts: 1247
|
Posted: Mon Jun 11, 2007 4:19 am Post subject: |
|
|
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 |
|
 |
Laszlo
Joined: 14 Feb 2005 Posts: 3942 Location: Pittsburgh
|
Posted: Mon Jun 11, 2007 6:05 am Post subject: |
|
|
| Thanks! It works equally well, does not need the external dll and the script is shorter. What more can we desire? |
|
| Back to top |
|
 |
Slaya Guest
|
|
| Back to top |
|
 |
Sean
Joined: 12 Feb 2007 Posts: 1247
|
Posted: Fri Jul 20, 2007 3:09 am Post subject: Re: Help needed |
|
|
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 |
|
 |
Mustang
Joined: 17 May 2007 Posts: 362 Location: England
|
Posted: Thu Jan 03, 2008 10:52 pm Post subject: |
|
|
| 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
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 |
|
 |
|
|
You can post new topics in this forum You can reply to topics in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|