Hi, I'm trying to do something similar to this, but with AHK:
https://stackoverflow.com/questions/405 ... n-crashing
so far I have this, but its not working:
http://p.ahkscript.org/?p=63cf6d92
Any help would be appreciated
DllCall, DrawTextW Topic is solved
Re: DllCall, DrawTextW
I will pay someone if they can help me
Re: DllCall, DrawTextW
Why is ProcessID wrapped in %?
Re: DllCall, DrawTextW
I've tried it with % and without and neither works.kczx3 wrote:Why is ProcessID wrapped in %?
Re: DllCall, DrawTextW
This is not working, but thought I would share it anyway.
The second try is based on this code
Code: Select all
#SingleInstance, force
WH_CALLWNDPROC := 4
WH_CALLWNDPROCRET := 12
libraryHandle := DllCall("LoadLibrary", "Str", "user32.dll", "Ptr")
DrawTextWAddress := DllCall("GetProcAddress", "Ptr", libraryHandle, "AStr", "DrawTextW", "Ptr")
TestHook := DllCall("SetWindowsHookEx", "Int", WH_CALLWNDPROC, "Ptr", DrawTextWAddress, "Ptr", libraryHandle, "Ptr", 0)
MsgBox, % TestHook
DllCall("UnhookWindowsHookEx", "Ptr", TestHook)
CallBack := RegisterCallback("TestProc", "Fast")
ThisLibAddress := DllCall("GetModuleHandle", "Ptr", 0)
TestHook := DllCall("SetWindowsHookEx", "Int", WH_CALLWNDPROC, "Ptr", CallBack, "Ptr", ThisLibAddress, "Ptr", 0)
MsgBox, % TestHook
DllCall("UnhookWindowsHookEx", "Ptr", TestHook)
return
TestProc(nCode, wParam, lParam) {
Critical
ToolTip, % lParam
return DllCall("CallNextHookEx", "Ptr", 0, "Int", nCode, "Ptr", wParam, "Ptr", lParam)
}
Code: Select all
#Persistent
#SingleInstance, force
if(A_PtrSize != 4) {
SplitPath, % A_AHKPath, , folder
Run, % folder "\AutoHotkeyU32.exe " """" A_ScriptFullPath """"
ExitApp
}
OnExit, Unhook
WH_KEYBOARD_LL := 13
WH_MOUSE_LL := 14
hHookKeybd := SetWindowsHookEx(WH_KEYBOARD_LL, RegisterCallback("Keyboard", "Fast"))
hHookMouse := SetWindowsHookEx(WH_MOUSE_LL, RegisterCallback("MouseMove", "Fast"))
Return
Unhook:
UnhookWindowsHookEx(hHookKeybd)
UnhookWindowsHookEx(hHookMouse)
ExitApp
Keyboard(nCode, wParam, lParam) {
Static WM_KEYDOWN := 0x100, WM_KEYUP := 0x101
Critical
SetFormat, Integer, H
if(wParam = WM_KEYDOWN || wParam = WM_KEYUP) {
KeyName := GetKeyName("vk" NumGet(lParam+0, 0))
Tooltip, % (wParam = 0x100) ? KeyName " Down" : KeyName " Up"
}
Return CallNextHookEx(nCode, wParam, lParam)
}
MouseMove(nCode, wParam, lParam) {
Critical
SetFormat, Integer, D
if(!nCode && (wParam = 0x200)) {
Tooltip, % "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, "Ptr", pfn, "Ptr", DllCall("GetModuleHandle", "Ptr", 0), "Ptr", 0)
}
UnhookWindowsHookEx(hHook) {
Return DllCall("UnhookWindowsHookEx", "Ptr", hHook)
}
CallNextHookEx(nCode, wParam, lParam, hHook = 0) {
Return DllCall("CallNextHookEx", "Ptr", hHook, "Int", nCode, "Ptr", wParam, "Ptr", lParam)
}
Please excuse my spelling I am dyslexic.
Re: DllCall, DrawTextW
Capn odin, for the hook setups, try to replace DllCall("GetModuleHandle", "Ptr", 0) with 0. If the problem is with the hooks that is. I'm on the phone so typing and reading is awkward.
Edit
Edit
Cheers.SetWindowsHookEx wrote:The hMod parameter must be set to NULL if the dwThreadId parameter specifies a thread created by the current process and if the hook procedure is within the code associated with the current process.
Re: DllCall, DrawTextW
Thank you. I will try these ideas.
Re: DllCall, DrawTextW Topic is solved
This will never work because:
You might find this AhkHook project to be far more simple.
If all fails, just write a DLL that uses MinHook in C. This is my favourite way as it's the only way that gives me full control of everything from top to bottom, which I need for ways to have my DLL automatically loaded by a remote process without manual injection (making a proxy DLL that assumes the name of another non-KnownDLL DLL? Great, just export the functions of the original DLL and forward them. Using a fake Application Verifier DLL? Great, you can actually handle the "DLL_PROCESS_VERIFIER" condition in DllMain yourself. Your target program links to user32.dll and you want to use AppInit_DLLs? Great, you're actually able to use DllMain to do what you want. [I'd love to be proven wrong here, but I think AutoHotkey_H.dll's mechanism for automatically loading a certain-named script file is disabled, meaning it can't be used in that situation]).
- SetWindowsHookEx isn't designed for hooking arbitrary functions; there's a reason why libraries like EasyHook (mentioned in the SO link in your first post) exist
- A WH_CALLWNDPROC hook procedure is meant to be located in the process itself. If it's in a DLL, Windows loads it into the remote process for you. With an AutoHotkey script such as one in your example, it exists only in AutoHotkey.exe and so Notepad.exe will never even look at it
You might find this AhkHook project to be far more simple.
If all fails, just write a DLL that uses MinHook in C. This is my favourite way as it's the only way that gives me full control of everything from top to bottom, which I need for ways to have my DLL automatically loaded by a remote process without manual injection (making a proxy DLL that assumes the name of another non-KnownDLL DLL? Great, just export the functions of the original DLL and forward them. Using a fake Application Verifier DLL? Great, you can actually handle the "DLL_PROCESS_VERIFIER" condition in DllMain yourself. Your target program links to user32.dll and you want to use AppInit_DLLs? Great, you're actually able to use DllMain to do what you want. [I'd love to be proven wrong here, but I think AutoHotkey_H.dll's mechanism for automatically loading a certain-named script file is disabled, meaning it can't be used in that situation]).
Re: DllCall, DrawTextW
Thank you very much. I will look into those ideas.
Who is online
Users browsing this forum: mikeyww, prototype_zero, w_i_k_i_d and 339 guests