"KeyWait" - press key valid only if ...

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
teosc
Posts: 54
Joined: 17 Jun 2017, 04:56

"KeyWait" - press key valid only if ...

03 Feb 2018, 11:16

I have a loop routine with a "IF" subruotine already inside

I've been shaking my head for 2 days without results, ask:
Is it possible in any way to specify that the KeyWait must be valid only if the mouse is over a certain window %var%?

my script, I would like to limit the K press valid only with mouse on window %var%

Code: Select all


loop
{
ifwinactive ahk_group xxx
{
wingettitle, Light, A
WinGetPos, x, y, w, h, A
Gui, +Lastfound +Toolwindow
iw:= w + 24
ih:= h + 24
w:= w + 42
h:= h + 42
x:= x - 2 - border_thickness k
y:= y - 2 - border_thickness
Gui, Color, FFFF00
Gui, -Caption
WinSet, Region, 0-0 %w%-0 %w%-%h% 0-%h% 0-0 %border_thickness%-%border_thickness% %iw%-%border_thickness% %iw%-%ih% %border_thickness%-%ih% %border_thickness%-%border_thickness%
Gui, Show, w%w% h%h% x%x% y%y% Noactivate
KeyWait k, D
Gui, Destroy
Sleep, 50
winwaitnotactive, %Light%
}
}
Osprey
Posts: 453
Joined: 18 Nov 2017, 05:50

Re: "KeyWait" - press key valid only if ...

03 Feb 2018, 16:09

Try something like this:

Code: Select all

loop
{
ifwinactive ahk_group xxx
{
wingettitle, Light, A
WinGetPos, x, y, w, h, A
Gui, +Lastfound +Toolwindow
iw:= w + 24
ih:= h + 24
w:= w + 42
h:= h + 42
x:= x - 2 - border_thickness k
y:= y - 2 - border_thickness
Gui, Color, FFFF00
Gui, -Caption
WinSet, Region, 0-0 %w%-0 %w%-%h% 0-%h% 0-0 %border_thickness%-%border_thickness% %iw%-%border_thickness% %iw%-%ih% %border_thickness%-%ih% %border_thickness%-%border_thickness%
Gui, Show, w%w% h%h%
OnMessage(0x200, "MouseOver")
}
}

MouseOver()
{
  global
  
  Ifwinactive, %light%
  {
    KeyWait k, D
    Gui, Destroy
    Sleep, 50
    winwaitnotactive, %Light%
  }
}
teosc
Posts: 54
Joined: 17 Jun 2017, 04:56

Re: "KeyWait" - press key valid only if ...

03 Feb 2018, 17:15

Osprey wrote:Try something like this:
....
Thanks osprey for the answer.
Your approach unfortunately does not work.

For the control K press valid only with mouse on window %light%, I just tried to replace the section:

Code: Select all

 Ifwinactive, %light%
  {
with:

Code: Select all

MouseGetPos ,,, mousehwnd
if (mousehwnd = WinExist ("light")) {
.....
}
... but even so it does not work
Osprey
Posts: 453
Joined: 18 Nov 2017, 05:50

Re: "KeyWait" - press key valid only if ...

03 Feb 2018, 18:46

I thought that you wanted KeyWait to trigger over the GUI. If you want it to trigger over the original window, I think that setting up a hotkey for "k" may be more suitable.

Try this:

Code: Select all

;loop
;{
ifwinactive ahk_group xxx
{
wingettitle, Light, A
WinGetPos, x, y, w, h, A
Gui, +Lastfound +Toolwindow ; +HwndMyGuiHwnd
iw:= w + 24
ih:= h + 24
w:= w + 42
h:= h + 42
x:= x - 2 - border_thickness k
y:= y - 2 - border_thickness
Gui, Color, FFFF00
Gui, -Caption
WinSet, Region, 0-0 %w%-0 %w%-%h% 0-%h% 0-0 %border_thickness%-%border_thickness% %iw%-%border_thickness% %iw%-%ih% %border_thickness%-%ih% %border_thickness%-%border_thickness%
Gui, Show, w%w% h%h% NoActivate, %Light%
}
;}

~k::MouseMove(Light)

MouseMove(vWin)
{
  Ifwinactive, %vWin%
  {
    WinGetPos, x, y, w, h, %vWin%
    CoordMode, Mouse, Screen
    MouseGetPos, MouseX, MouseY

    If MouseX between %x% and % x+w
      If MouseY between %y% and % y+h
        Gui, Destroy
  }
}

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Joey5, mcd, NullRefEx and 127 guests