I have a GUI that notifies the user via a tooltip whenever the cursor is inside of it. And, when the cursor leaves the GUI, the tooltip also notifies of the exit.
Here is what I would like to try:
I have 4 keystrokes: x, e, m, s
The instant the cursor enters inside the GUI, a tooltip will appear, which would say 'X'
If the cursor has been inside the GUI for 1 second, then the tooltip changes to 'E'.
If the cursor has been inside the GUI for 2 seconds, then the tooltip changes to 'M'.
Finally, if the cursor has been inside the GUI for 3 seconds, the tooltip changes to 'S'.
After 4 seconds, the tooltips would repeat over and over again until the cursor has exited the GUI, at which point the loop would start over again the next time the cursor re-enters the GUI.
And the last part - if the cursor exits the GUI at between 1 and 2 seconds (as an example), then the script would send keystroke E to the active window, and this is because at between the 1 and 2 second mark, the tooltip was displaying 'E'.
As another example, if the cursor exits the GUI at between 3 and 4 seconds, it would send keystroke 'S' because at between 3 and 4 seconds the tooltip is displaying 'S'.
I think I have made this sound much more complicated than it probably is - I have accomplished this type of script using a mouse button (while getkeystate "f", "P") for example, and it works with keys and mouse buttons - but I want this to work while the cursor is hovering ontop of the GUI.
Am I looking at some kind of a timer to achieve this?
Code: Select all
#SingleInstance force
Gui,mygui:new
Gui,mygui: +AlwaysOnTop +HwndGameListhwnd
Gui,mygui:add,text,w50 h50,MYGUI
Gui,mygui:show
OnMessage(0x200, "msgHandler")
OnMessage(0x2A3, "msgHandler")
return
msgHandler(wParam, lParam, msg, hwnd)
{
static isTracking
if msg = 0x200
{
if !isTracking
tooltip, CURSOR IS INSIDE THE GUI
isTracking := setMouseLeaveTracking(hwnd)
}
else if msg = 0x2A3
{
tooltip, CURSOR IS OUTSIDE THE GUI
isTracking := False
}
return
}
setMouseLeaveTracking(hwnd)
{
static v
if !v
{
VarSetCapacity(v, size := A_Ptrsize = 8 ? 24 : 16, 0)
NumPut(size, v, 0, "UInt") ; cbSize
NumPut(0x00000002, v, 4, "UInt") ; dwFlags (TME_LEAVE)
NumPut(hwnd, v, 8, "Ptr") ; HWND
NumPut(0, v, A_Ptrsize = 8 ? 16 : 12, "UInt") ; dwHoverTime (ignored)
}
return DllCall("TrackMouseEvent", "Ptr", &v) ; Non-zero on success
}