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 determine if mouse is hovering over text edit ctrl?

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



Joined: 19 Jan 2006
Posts: 15
Location: Heidelberg

PostPosted: Fri Feb 10, 2006 12:54 pm    Post subject: how to determine if mouse is hovering over text edit ctrl? Reply with quote

hi! i have the following question:

i want to know whether the mouse is currently hovering over a text edit field, and if yes, send input to that field on pressing a mouse button.

i know that i can get a handle on the control using

Code:
MouseGetPos, , , , control


but i dont see how then to determine the TYPE of this control. i had a look at the "GuiControlGet" function, but if this offers a solution then i don't understand how...

any ideas? thanks a lot!
Back to top
View user's profile Send private message
toralf



Joined: 31 Jan 2005
Posts: 3910
Location: Bremen, Germany

PostPosted: Fri Feb 10, 2006 12:56 pm    Post subject: Reply with quote

what does the "control" var in the MouseGetPos command contain when you move the mouse over the control you want to check?
_________________
Ciao
toralf
Back to top
View user's profile Send private message Send e-mail Visit poster's website
rh



Joined: 19 Jan 2006
Posts: 15
Location: Heidelberg

PostPosted: Fri Feb 10, 2006 1:04 pm    Post subject: Reply with quote

that depends on the program. in some it says "Edit1", but for example in firefox it says "MozillaWindowClass1".
Back to top
View user's profile Send private message
PhiLho



Joined: 27 Dec 2005
Posts: 6836
Location: France (near Paris)

PostPosted: Fri Feb 10, 2006 3:25 pm    Post subject: Reply with quote

Bad example, Firefox is like Java programs, its interface is hand-made to ease the portability between systems.
You can still have the problem with Visual Basic or Delphi applications, which can name their control ThunderRT6TextBox1 or TEdit1...
A way to see if a control is an edit one is to send it some specific Windows message and see if the answer is consistent. A ListBox will ignore a EM_GETLINECOUNT.
Actually, you can do this with ControlGet:
Code:
MouseGetPos, , , id, control
ControlGet lc, LineCount, , %control%, ahk_id %id%

lc will be 0 for non-edit control, 1 or more for edit controls (including RichEdit ones).
I could have used:
Code:
EM_GETLINECOUNT = 0xBA
SendMessage EM_GETLINECOUNT, 0, 0, %control%, ahk_id %id%
lc := ErrorLevel
with similar result.
_________________
vPhiLho := RegExReplace("Philippe Lhoste", "^(\w{3})\w*\s+\b(\w{3})\w*$", "$1$2")
Back to top
View user's profile Send private message Visit poster's website
evl



Joined: 24 Aug 2005
Posts: 1237

PostPosted: Fri Feb 10, 2006 3:41 pm    Post subject: Reply with quote

You can also check what type (shape) the mouse pointer is which may be an alternative.additional check you could make. When over text the mouse changes to an IBeam - this unfortunately doesn't differentiate between edit controls and ordinary text on a web page, for example.

From the manual:

Quote:

A_Cursor:
The type of mouse cursor currently being displayed. It will be one of the following words: AppStarting, Arrow, Cross, Help, IBeam, Icon, No, Size, SizeAll, SizeNESW, SizeNS, SizeNWSE, SizeWE, UpArrow, Wait, Unknown. The acronyms used with the size-type cursors are compass directions, e.g. NESW = NorthEast+SouthWest. The hand-shaped cursors (pointing and grabbing) are classfied as Unknown.

If this variable's contents are fetched repeatedly at a high frequency (i.e. every 500 ms or faster), it will probably disrupt the user's ability to double-click. There is no known workaround.
Back to top
View user's profile Send private message
rh



Joined: 19 Jan 2006
Posts: 15
Location: Heidelberg

PostPosted: Fri Feb 10, 2006 4:40 pm    Post subject: Reply with quote

thanks Philho, that is a nice solution. unfortunately, for firefox it does not work, but well, i have to handle that case individually.

so here's my code:

Code:
F13::
MouseGetPos, , , id, control
ControlGet lc, LineCount, , %control%, ahk_id %id%
if (lc!=0 or control="MozillaWindowClass1")
{
    MouseClick
    Send, {End}+{Home}{Del}
}
return


as you can see, it is useful for emptying e.g. the adress bar of a browser when wanting to visit another webpage.
Back to top
View user's profile Send private message
PhiLho



Joined: 27 Dec 2005
Posts: 6836
Location: France (near Paris)

PostPosted: Fri Feb 10, 2006 5:26 pm    Post subject: Reply with quote

So, if you run this on an hotkey, why do you want to check the kind of control? One could suppose you would only hit this key on purpose, when mouse is at the right location.
Is it a kind of foolproof control, to avoid errors?
Anyway, I am happy it works for you.
_________________
vPhiLho := RegExReplace("Philippe Lhoste", "^(\w{3})\w*\s+\b(\w{3})\w*$", "$1$2")
Back to top
View user's profile Send private message Visit poster's website
rh



Joined: 19 Jan 2006
Posts: 15
Location: Heidelberg

PostPosted: Fri Feb 10, 2006 7:14 pm    Post subject: Reply with quote

PhiLho wrote:
Is it a kind of foolproof control, to avoid errors?


well, when i asked, my code was still a bit different:

i was sending CTRL-A,DEL. when doing this by hazard on the desktop for example, then this would result in deleting all files (well there was always the confirmation question, but you never know...). therefore i wanted to add some safety, especially since the concerning button on my mouse is placed in a location where from time to time one hit's it accidently.

now after i changed the code, it should be safer in any case, but "del" is always a potentially evil key... Wink
Back to top
View user's profile Send private message
SKAN



Joined: 26 Dec 2005
Posts: 8688

PostPosted: Sat Feb 11, 2006 4:52 am    Post subject: Reply with quote

Try this Solution by Shimanov
_________________
URLGet - Internet Explorer based Downloader
Back to top
View user's profile Send private message Send e-mail
Display posts from previous:   
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