AutoHotkey Community

It is currently May 27th, 2012, 6:53 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 9 posts ] 
Author Message
PostPosted: February 10th, 2006, 1:54 pm 
Offline

Joined: January 19th, 2006, 4:16 pm
Posts: 15
Location: Heidelberg
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!


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 10th, 2006, 1:56 pm 
Offline

Joined: January 31st, 2005, 9:50 am
Posts: 3910
Location: Bremen, Germany
what does the "control" var in the MouseGetPos command contain when you move the mouse over the control you want to check?

_________________
Ciao
toralf
Image


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 10th, 2006, 2:04 pm 
Offline

Joined: January 19th, 2006, 4:16 pm
Posts: 15
Location: Heidelberg
that depends on the program. in some it says "Edit1", but for example in firefox it says "MozillaWindowClass1".


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 10th, 2006, 4:25 pm 
Offline

Joined: December 27th, 2005, 1:46 pm
Posts: 6837
Location: France (near Paris)
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.

_________________
Image vPhiLho := RegExReplace("Philippe Lhoste", "^(\w{3})\w*\s+\b(\w{3})\w*$", "$1$2")


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 10th, 2006, 4:41 pm 
Offline

Joined: August 24th, 2005, 5:17 pm
Posts: 1237
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.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 10th, 2006, 5:40 pm 
Offline

Joined: January 19th, 2006, 4:16 pm
Posts: 15
Location: Heidelberg
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.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 10th, 2006, 6:26 pm 
Offline

Joined: December 27th, 2005, 1:46 pm
Posts: 6837
Location: France (near Paris)
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.

_________________
Image vPhiLho := RegExReplace("Philippe Lhoste", "^(\w{3})\w*\s+\b(\w{3})\w*$", "$1$2")


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 10th, 2006, 8:14 pm 
Offline

Joined: January 19th, 2006, 4:16 pm
Posts: 15
Location: Heidelberg
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:


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 11th, 2006, 5:52 am 
Offline
User avatar

Joined: December 26th, 2005, 4:40 pm
Posts: 8776
Try thisSolution by Shimanov

_________________
URLGet - Internet Explorer based Downloader
StartEx - Portable Shortcut Link


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 9 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: migz99, sjc1000, Yahoo [Bot] and 67 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group