how to get the message of notepad.exe

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
xuezhe
Posts: 91
Joined: 06 Jan 2016, 11:02

how to get the message of notepad.exe

14 Oct 2017, 20:06

Code: Select all

hwnd:=ProcessExist("Notepad.exe") ;if exist,return ahk_pid or return 0
hwnd:=format("0x{:X}",hwnd)
WH_GETMESSAGE := 3 
hooker:=DllCall("SetWindowsHookEx", "int",WH_GETMESSAGE, "Uint", RegisterCallback("Navigate", "Fast"), "Uint", DllCall("GetModuleHandle", "Uint", 0), "Uint",hwnd)

Return

Navigate(nCode, wParam, lParam)
{
   Critical
   ToolTip % nCode  "`n" wParam "`n" lParam
   Return DllCall("CallNextHookEx", "Uint", hooker, "int", nCode, "Uint", wParam, "Uint", lParam)
}

ProcessExist(ProcessName){ 
Process,Exist,% ProcessName 
return ErrorLevel
}
it doesn't work in AHK_L.
teadrinker
Posts: 4391
Joined: 29 Mar 2015, 09:41
Contact:

Re: how to get the message of notepad.exe

14 Oct 2017, 20:49

There is no way to get messages from windows belonging to different processes, using pure AHK, because the hook procedure must be contained in the external dll in that case.
lpfn [in]

Type: HOOKPROC

A pointer to the hook procedure. If the dwThreadId parameter is zero or specifies the identifier of a thread created by a different process, the lpfn parameter must point to a hook procedure in a DLL. Otherwise, lpfn can point to a hook procedure in the code associated with the current process.
xuezhe
Posts: 91
Joined: 06 Jan 2016, 11:02

Re: how to get the message of notepad.exe

14 Oct 2017, 20:54

but the following ahk can work.

Code: Select all

#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
#Persistent
SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.
SetFormat, integer, Hex
OnExit, Unhook

hHookKeybd := SetWindowsHookEx(WH_KEYBOARD_LL := 13, RegisterCallback("LowLevelKeyboardProc", "Fast"))
Return
SetWindowsHookEx(idHook, pfn)
{
   Return DllCall("SetWindowsHookEx", "int", idHook, "Uint", pfn, "Uint", DllCall("GetModuleHandle", "Uint", 0), "Uint", 0)
}




LowLevelKeyboardProc(nCode, wParam, lParam)
{
   Critical
   
   vk := NumGet(lParam+0)				
   sc := NumGet(lParam+4)			
   ToolTip %nCode%---%wParam%---%lParam%---%vk%---%sc%
   
   Return CallNextHookEx(nCode, wParam, lParam)
}
CallNextHookEx(nCode, wParam, lParam, hHook = 0)
{
   Return DllCall("CallNextHookEx", "Uint", hHook, "int", nCode, "Uint", wParam, "Uint", lParam)
}



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



Unhook:
UnhookWindowsHookEx(hHookKeybd)		
ExitApp


teadrinker
Posts: 4391
Joined: 29 Mar 2015, 09:41
Contact:

Re: how to get the message of notepad.exe

14 Oct 2017, 20:58

Yes, this rule doesn't work for WH_KEYBOARD_LL and WH_MOUSE_LL.
xuezhe
Posts: 91
Joined: 06 Jan 2016, 11:02

Re: how to get the message of notepad.exe

14 Oct 2017, 21:03

teadrinker wrote:Yes, this rule doesn't work for WH_KEYBOARD_LL and WH_MOUSE_LL.
ahk_h v2 ,it contains a autohotkey.dll.Can it get the message of Notepad.exe.


the following ahk can work ?
https://autohotkey.com/boards/viewtopic.php?f=6&t=830
teadrinker
Posts: 4391
Joined: 29 Mar 2015, 09:41
Contact:

Re: how to get the message of notepad.exe

14 Oct 2017, 21:16

ahk_h v2 ,it contains a autohotkey.dll.Can it get the message of Notepad.exe.
Sorry, i'm not sure about it, because hook procedures may vary in different cases.
the following ahk can work ?
Yes, but it can't catch window messages, it just monitors system events like creation/destroing/minimizing/moving windows, appearing menues, and so on.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Google [Bot] and 182 guests