 |
AutoHotkey Community Let's help each other out
|
| View previous topic :: View next topic |
| Author |
Message |
XurF9M
Joined: 13 May 2008 Posts: 6
|
Posted: Tue May 13, 2008 7:04 pm Post subject: How to block mouse input for a named window? |
|
|
Hi,
I have a console application that requires users to exit via menu options. unfortunately it also has an 'x' control on the window that will close it(!).
Is there a way to monitor mouse clicks and disable input if the mouse cursor is over that window? Perhaps with MouseGetPos and BlockInput?
Thanks |
|
| Back to top |
|
 |
heresy
Joined: 11 Mar 2008 Posts: 291
|
Posted: Wed May 14, 2008 2:01 am Post subject: |
|
|
| Code: | MouseBlock:
WinWaitActive, WinTitle ;put your Window Title here
BlockInput, MouseMove ;kill mouse interaction
Loop {
Sleep, 1
IfWinNotActive ;use last found window
{
BlockInPut, MouseMoveOff ;restore mouse interaction
Break
}
}
GoSub, MouseBlock ;go back to first |
try this
and use alt+tab to restore mouse interaction _________________ Easy WinAPI - Dive into Windows API World
Benchmark your AutoHotkey skills at PlayAHK.com |
|
| Back to top |
|
 |
sinkfaze
Joined: 19 Mar 2008 Posts: 140
|
Posted: Wed May 14, 2008 4:22 am Post subject: |
|
|
Here's an untested idea.
If your "X" button is like mine it changes colors when the mouse hovers over it, so use SetTimer to create a timed PixelSearch of the area of color in the horizontal center of the "X" button (those colors IMO are the most distinctively different between when the mouse hovers over them and when it doesn't). If it finds the color which is only present when the mouse is hovering over it, it disables the left mouse button; when it stops finding that color it returns the button to its normal function.
You can use Window Spy or toralf's AHK Window Info utility to pick out the specific hex code for the color when highlighted (it will also help you locate a narrower range of pixels to search for the color). If you do attempt this make sure to establish a hotkey that will disable the timer in case you begin to run into some undesired results. _________________ Have trouble searching the site for information? Try Quick Search for Autohotkey. |
|
| Back to top |
|
 |
Z Gecko Guest
|
Posted: Wed May 14, 2008 4:36 am Post subject: |
|
|
or, kind off bruteforce:
Remove the whole titlebar of that window, with
WinSet, Style, -0xC00000, ...
no one can click what´s not there  |
|
| Back to top |
|
 |
XurF9M
Joined: 13 May 2008 Posts: 6
|
Posted: Thu May 15, 2008 4:27 pm Post subject: |
|
|
Thanks for all the suggestions.
The style change evidently won't work with this window
The 'x' does not change color but perhaps I can still search for some distinctive part of the window.
The MouseBlock code certainly works, thanks. Maybe I can modify it to use WinGetActiveTitle so that the mouse will work outside the window without Alt-Tab |
|
| Back to top |
|
 |
n-l-i-d Guest
|
|
| Back to top |
|
 |
ImprisonedPride
Joined: 30 Apr 2008 Posts: 34
|
Posted: Thu May 15, 2008 5:43 pm Post subject: |
|
|
Correct me if I'm wrong, because I'm still learning AHK too, but wouldn't the simplest way to get rid of that be:
I guess if you still wanted the min/max buttons it wouldn't work. |
|
| Back to top |
|
 |
Micahs
Joined: 01 Dec 2006 Posts: 339
|
Posted: Fri May 16, 2008 6:29 am Post subject: |
|
|
This will prevent the user from clicking on the titlebar close button and the icon while allowing window drag, resize, scrolling. It uses a variation of my Zero-Focus technique to disable the left mouse button while over the icon and X button and disable the right mouse button over the entire titlebar. It also prevents Alt-F4 while the desired window is active.
This will not prevent the user from right-clicking on the taskbar button and selecting 'close', however. If there is any interest I will look into adding it. It also does not prevent task manager termination.
| Code: |
targettitle = SciTE ;window title to target
caseSensitive = false ;scite or SciTE
SetTitleMatchMode, 2 ;partial match
CoordMode, MOUSE, SCREEN
virtualkey = VK0E
SysGet, SM_CXSIZE, 30 ;get dimensions of caption area buttons
SysGet, SM_CYSIZE, 31
SysGet, SM_CYCAPTION, 4 ;get height of caption area
SysGet, SM_CYEDGE, 46 ;thickness of the 3-d border
GroupAdd, id, %targettitle%
SetTimer, blockit, 100
Return
blockit:
match=0
MouseGetPos,x,y,id
WinGetTitle, title, ahk_id %id%
WinGetPos, wx, wy, ww, wh, ahk_id %id%
If(A_TitleMatchMode = 1) ;title must start with targettitle
{ If InStr(title, targettitle,%caseSensitive%, 1)
{ match=1
}
}
Else If(A_TitleMatchMode = 2) ;title must contain targettitle
{ IfInString, title, %targettitle%
{ match=1
}
}
Else If(A_TitleMatchMode = 3) ;title must equal targettitle
{ If(targettitle = title)
{ match=1
}
}
titlebar := wy + SM_CYCAPTION + (SM_CYEDGE * 2)
titleicon := wx + SM_CXSIZE + SM_CYEDGE
titleclose := wx + ww - SM_CXSIZE - (SM_CYEDGE * 2)
If(match and y < titlebar)
{ If(x < titleicon or x > titleclose)
{ Hotkey, *LButton, On
Hotkey, *LButton up, On
lstate=Left Remap On
}
Else
{ Hotkey, *LButton, Off
Hotkey, *LButton up, Off
lstate=Left Remap Off
}
Hotkey, *RButton, On
Hotkey, *RButton up, On
rstate=Right Remap On
}
Else
{ Hotkey, *LButton, Off
Hotkey, *LButton up, Off
Hotkey, *RButton, Off
Hotkey, *RButton up, Off
lstate=Left Remap Off
rstate=Right Remap Off
}
;~ ToolTip,left state: %lstate%`nright state: %rstate%`nmatch: %match%`n`nx: %x%`nicon: %titleicon% <--> close: %titleclose%`n`ny: %y%`ntitlebar: %titlebar%,750,30,19
Return
#IfWinActive, ahk_group id
!F4::
#IfWinActive
*LButton:: ;map left click to the Virtual Key - VK does not stand for Voigt-Kampff
SetKeyDelay -1
Send {Blind}{%virtualkey% Up}
Return
*LButton Up:: ;map left click to the Virtual Key
SetKeyDelay -1
Send {Blind}{%virtualkey% Up}
Return
*RButton:: ;map right click to the Virtual Key
SetKeyDelay -1
Send {Blind}{%virtualkey% Up}
Return
*RButton Up:: ;map right click to the Virtual Key
SetKeyDelay -1
Send {Blind}{%virtualkey% Up}
Return |
Maybe simpler, but not as much fun! Also, that will only work on your gui, you'd have to use winset for other windows. _________________
 |
|
| 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
|