AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

How to block mouse input for a named window?

 
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Ask for Help
View previous topic :: View next topic  
Author Message
XurF9M



Joined: 13 May 2008
Posts: 6

PostPosted: Tue May 13, 2008 7:04 pm    Post subject: How to block mouse input for a named window? Reply with quote

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
View user's profile Send private message
heresy



Joined: 11 Mar 2008
Posts: 291

PostPosted: Wed May 14, 2008 2:01 am    Post subject: Reply with quote

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
View user's profile Send private message
sinkfaze



Joined: 19 Mar 2008
Posts: 140

PostPosted: Wed May 14, 2008 4:22 am    Post subject: Reply with quote

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
View user's profile Send private message
Z Gecko
Guest





PostPosted: Wed May 14, 2008 4:36 am    Post subject: Reply with quote

or, kind off bruteforce:
Remove the whole titlebar of that window, with
WinSet, Style, -0xC00000, ...
no one can click what´s not there Smile
Back to top
XurF9M



Joined: 13 May 2008
Posts: 6

PostPosted: Thu May 15, 2008 4:27 pm    Post subject: Reply with quote

Thanks for all the suggestions.

The style change evidently won't work with this window Sad
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
View user's profile Send private message
n-l-i-d
Guest





PostPosted: Thu May 15, 2008 4:53 pm    Post subject: Reply with quote

1. Google on AutoHotkey forum for "disable close button"
2. Find 2nd result, the solution by SKAN: How to Disable ( Grey-out ) the Close Button?
3. ??? (scream for joy, holler and faint?)
4. Profit!

Wink
Back to top
ImprisonedPride



Joined: 30 Apr 2008
Posts: 34

PostPosted: Thu May 15, 2008 5:43 pm    Post subject: Reply with quote

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:

Code:

Gui, -SysMenu


I guess if you still wanted the min/max buttons it wouldn't work.
Back to top
View user's profile Send private message
Micahs



Joined: 01 Dec 2006
Posts: 339

PostPosted: Fri May 16, 2008 6:29 am    Post subject: Reply with quote

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


Quote:
simplest way
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
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Ask for Help All times are GMT
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group