AutoHotkey Community

It is currently May 27th, 2012, 1:33 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 18 posts ]  Go to page 1, 2  Next
Author Message
 Post subject: Have #SetTitleMatchMode
PostPosted: November 17th, 2009, 10:40 am 
Offline

Joined: February 2nd, 2008, 4:35 am
Posts: 643
As well as "positional" SetTitleMatchMode (not already so??) --> "positional" only applies to #IfWinExist/Active, which is "static" as opposed to SetTitleMatchMode which is "dynamic"

This is so for example
Code:
SetTitleMatchMode, RegEx
Hotkey, IfWinActive, .*Mozilla Firefox ahk_class MozillaUIWindowClass
Hotkey, $#d, Win_d

SetTitleMatchMode, 2
DetectHiddenWindows, On
Hotkey, IfWinActive, <within the title> ahk_class AutoHotkeyGUI
Hotkey, WheelDown, WheelDownRoutine
can work

* Edit: maybe it does work .. will have to test specifically for above, but the below definately does not work
--> No, it seems that "Hotkey, IfWinActive/Exist" (& #IfWin...) don't support RegEx

Code:
SetTitleMatchMode, 1|2|3|RegEx  ;can only use ONE (only ONE instance (in autoexec section) seems to affect the :: hotkeys after Exit)

Exit

;SetTitleMatchMode, RegEx   ;(want)
#IfWinActive, .*Mozilla Firefox ahk_class MozillaUIWindowClass
$#d::Gosub Win_d

;SetTitleMatchMode, 2   ;(want)   (can't have these commands here, as won't get executed)
;DetectHiddenWindows, On   ;(want)
#IfWinActive, <within the title> ahk_class AutoHotkeyGUI
WheelDown::Gosub WheelDownRoutine


Using the proposed #SetTitleMatchMode directive (used for :: hotkeys)...

Code:
Exit

#SetTitleMatchMode, RegEx
#IfWinActive, .*Mozilla Firefox ahk_class MozillaUIWindowClass
$#d::Gosub Win_d

#SetTitleMatchMode, 2
#DetectHiddenWindows, On
#IfWinActive, <within the title> ahk_class AutoHotkeyGUI
WheelDown::Gosub WheelDownRoutine



* Also DetectHiddenWindows


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 17th, 2009, 2:49 pm 
Offline

Joined: February 2nd, 2008, 4:35 am
Posts: 643
Ok, scratch all the RegEx bits, as #IfWin.../Hotkey, IfWin... doesn't currently support RegEx [yet]

Instead consider if want to use say S.T.M.Mode,1 and S.T.M.Mode,2 for :: hotkeys


Last edited by a_h_k on November 19th, 2009, 1:27 pm, edited 1 time in total.

Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 19th, 2009, 12:40 pm 
Offline

Joined: October 17th, 2006, 4:15 pm
Posts: 7502
Location: Australia
I would prefer something more concise, like ahk_re only more generic. It would probably also be easier to implement, as the matching mode can be set temporarily during matching (based on a keyword in the title text) rather than stored as a separate option within each hotkey variant.
Quote:
[#]IfWin.. doesn't currently support RegEx [yet]
It surely does if you use SetTitleMatchMode RegEx correctly...


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 19th, 2009, 1:47 pm 
Offline

Joined: February 2nd, 2008, 4:35 am
Posts: 643
Sorry, that was incorrect
It should be "#IfWin.../Hotkey, IfWin... " (i have made the correction)

So RegEx works with #IfWin.../Hotkey, IfWin... ?


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 19th, 2009, 1:52 pm 
Offline

Joined: October 17th, 2006, 4:15 pm
Posts: 7502
Location: Australia
Yes.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 19th, 2009, 2:04 pm 
Offline

Joined: February 2nd, 2008, 4:35 am
Posts: 643
That's very interesting .. so how come this works
Code:
SetTitleMatchMode, 2
Hotkey, IfWinActive, Mozilla Firefox
Hotkey, ...
...

and if i change JUST this, then the following doesn't work
Code:
SetTitleMatchMode, RegEx
Hotkey, IfWinActive, .*Mozilla Firefox  ;even just "Mozilla Firefox" fails
Hotkey, ...
...

???


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 20th, 2009, 9:31 am 
Offline

Joined: October 17th, 2006, 4:15 pm
Posts: 7502
Location: Australia
Code:
SetTitleMatchMode, RegEx
Hotkey, IfWinActive, .*Mozilla Firefox
Hotkey, RCtrl, Test
return
Test:
MsgBox
return

Works for me.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 20th, 2009, 2:08 pm 
Offline

Joined: February 2nd, 2008, 4:35 am
Posts: 643
A bit of inexperience on my part ..

Didnt realize brackets were a symbol
However this didnt work: GroupAdd, Win_x, Win-x `(Firefox`)`.ahk
Nor even: GroupAdd, Win_x, Win-x\s\s`(Firefox`)`.ahk
Is my syntax still not right?

Finally just used \Q..\E around whole thing, which resolve this particualar issue
. GroupAdd, Win_x, \QWin-x (Firefox).ahk\E
. GroupAdd, Win_x, \QWin-x (Firefox).exe\E

Hotkey, IfWinActive, ahk_group Win_x = now works for regex ׃)


HOWEVER, after much "reducing" of my problematic code, i now have the following issue to be resolved (maybe it's even an ahk BUG ???)
(i hope you don't mind testing it out)

Put in test.ahk, one at a time...

test 1 (1=2=v, 2=2=v)
Code:
#SingleInstance, Force
;----------------------------
SetTitleMatchMode, 2
Hotkey, IfWinActive, test.ahk
Hotkey, a, a
;----------------------------
;SetTitleMatchMode, 2
Hotkey, IfWinActive, test.ahk
Hotkey, d, d
;----------------------------
Gui, Add, Button
Gui, Show
pause
;----------------------------
a:
  msgbox,,,a,0.25
return
d:
 msgbox,,,d,0.25
return

test 2 (1=2=v, 2=re=v)
Code:
#SingleInstance, Force
;----------------------------
SetTitleMatchMode, 2
Hotkey, IfWinActive, test.ahk
Hotkey, a, a
;----------------------------
SetTitleMatchMode, RegEx
Hotkey, IfWinActive, \Qtest.ahk\E
Hotkey, d, d
;----------------------------
Gui, Add, Button
Gui, Show
pause
;----------------------------
a:
  msgbox,,,a,0.25
return
d:
 msgbox,,,d,0.25
return

test 3 (1=re=x, 2=2=v)
Code:
#SingleInstance, Force
;----------------------------
SetTitleMatchMode, RegEx
Hotkey, IfWinActive, \Qtest.ahk\E
Hotkey, a, a
;----------------------------
SetTitleMatchMode, 2
Hotkey, IfWinActive, test.ahk
Hotkey, d, d
;----------------------------
Gui, Add, Button
Gui, Show
pause
;----------------------------
a:
  msgbox,,,a,0.25
return
d:
 msgbox,,,d,0.25
return

test 4 (1=re=v, 2=re=v)
Code:
#SingleInstance, Force
;----------------------------
SetTitleMatchMode, RegEx
Hotkey, IfWinActive, \Qtest.ahk\E
Hotkey, a, a
;----------------------------
;SetTitleMatchMode, RegEx
Hotkey, IfWinActive, \Qtest.ahk\E
Hotkey, d, d
;----------------------------
Gui, Add, Button
Gui, Show
pause
;----------------------------
a:
  msgbox,,,a,0.25
return
d:
 msgbox,,,d,0.25
return


"According to hoyle", for test 3 the "a" won't pop-up (as doesnt on my pc), whereas all the rest will
My theory is that the "SetTitleMatchMode, 2" overrides the "SetTitleMatchMode, RegEx" (as its the last to be done, so stays at that thereafter), and that :. is like the typical dynamic, non-positional command (eg #NoTrayIcon) (ie can only be ONE such command in script)
For test 2, SetTitleMatchMode operates like #IfWin.. (ie "positional")
a_h_k wrote:
As well as "positional" SetTitleMatchMode (not already so??) --> "positional" only applies to #IfWinExist/Active, which is "static" as opposed to SetTitleMatchMode which is "dynamic"


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 20th, 2009, 2:40 pm 
Offline

Joined: October 17th, 2006, 4:15 pm
Posts: 7502
Location: Australia
a_h_k wrote:
Didnt realize brackets were a symbol
However this didnt work: GroupAdd, Win_x, Win-x `(Firefox`)`.ahk
Use \ as explained in the docs:
Quote:
Escaped characters: Most characters like abc123 can be used literally inside a regular expression. However, the characters \.*?+[{|()^$ must be preceded by a backslash to be seen as literal. For example, \. is a literal period and \\ is a literal backslash. Escaping can be avoided by using \Q...\E. For example: \QLiteral Text\E.
Source: Regular Expressions (RegEx) - Quick Reference

a_h_k wrote:
My theory is that the "SetTitleMatchMode, 2" overrides the "SetTitleMatchMode, RegEx"
Right. Wasn't that the point of this "wish"?
a_h_k wrote:
For test 2, SetTitleMatchMode operates like #IfWin.. (ie "positional")
No. The regular expression "test.ahk" matches any window with "test.ahk" in the title, where matching is case-sensitive and "." can match any character, including a literal dot. For instance, it will match "this is a test.ahk" (like mode 2) and "footest(ahk)" (unlike any other mode).


To be clear: window title matching uses the title match mode which is in effect at the time the window titles are compared. Any change to the setting applies to all subsequent uses of a WinTitle parameter in the current thread. If SetTitleMatchMode is used in the auto-execute section, it changes the default setting, which is used for new threads and #IfWin.

If I understand correctly, the point of #SetTitleMatchMode would be to override the title match mode used by subsequent #IfWin directives (or more technically accurate: subsequent hotkey variants based on those #IfWin directives).


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 21st, 2009, 8:02 am 
Offline

Joined: February 2nd, 2008, 4:35 am
Posts: 643
Lexikos wrote:
a_h_k wrote:
My theory is that the "SetTitleMatchMode, 2" overrides the "SetTitleMatchMode, RegEx"
Right. Wasn't that the point of this "wish"?
My original wish, is to have #SetTitleMatchMode a directive, so that differnet (static) #IfWin.. commands (& their subsequent hotkeys) can "pick-and-choose" which TitleMatchMode to obey (rather than ALL just obeying the SAME default or autexec TitleMatchMode setting)

a_h_k wrote:
My theory is that the "SetTitleMatchMode, 2" overrides the "SetTitleMatchMode, RegEx"
Concerns a slightly different topic - Hotkey,.. (dynamic) hotkeys
I think that this shouldn't happen, as "\Qtest.ahk\E" then obeys 2-mode & not it's intended RegEx mode
("Hotkey, IfWinActive, \Qtest.ahk\E" should obey regex-mode, and "Hotkey, IfWinActive, test.ahk" should obey 2-mode!!)
Lexikos wrote:
window title matching uses the title match mode which is in effect at the time the window titles are compared. Any change to the setting applies to all subsequent (ie below) (edit: no, after in time, not position) uses of a WinTitle parameter in the current thread

Lexikos wrote:
If I understand correctly, the point of #SetTitleMatchMode would be to override the title match mode used by subsequent #IfWin directives (or more technically accurate: subsequent hotkey variants based on those #IfWin directives)
Correct


Last edited by a_h_k on November 28th, 2009, 7:22 am, edited 1 time in total.

Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 26th, 2009, 7:02 am 
Offline

Joined: August 24th, 2005, 5:29 pm
Posts: 549
Location: Berlin / Germany
FYI, all you wish can be done with MatchMode RegEx:
Code:
#NoEnv
SetTitleMatchMode, RegEx
Gui, Show, w400 h400, My Test Gui
Hotkey, IfWinActive, ^My Test          ; MatchMode 1
Hotkey, 1, 1
Hotkey, IfWinActive, Test              ; MatchMode 2
Hotkey, 2, 2
Hotkey, IfWinActive, ^My Test Gui$     ; MatchMode 3
Hotkey, 3, 3
Hotkey, IfWinActive
Return
GuiClose:
Esc::
ExitApp
1:
2:
3:
MsgBox, %A_ThisLabel%
Return

_________________
nick :wink:


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 26th, 2009, 2:28 pm 
Offline

Joined: February 2nd, 2008, 4:35 am
Posts: 643
Yes i know that (like the code though ׃), but it would be "nice" to have a #SetTitleMatchMode (with your way all the :: hotkeys have to be changed to Hotkey hotkeys)

For any interested, the following thread covers the "issue" of only 1 SetTitleMatchMode being allowed/followed in main thread


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 26th, 2009, 3:28 pm 
Offline

Joined: August 24th, 2005, 5:29 pm
Posts: 549
Location: Berlin / Germany
Quote:
(with your way all the :: hotkeys have to be changed to Hotkey hotkeys)

Why should they have to be changed?

Help for #IfWin... wrote:
The title or partial title of the target window (the matching behavior is determined by SetTitleMatchMode as set in the auto-execute section).

So it's the same for #IfWin....

_________________
nick :wink:


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 27th, 2009, 6:55 am 
Offline

Joined: February 2nd, 2008, 4:35 am
Posts: 643
This will work
Code:
SetTitleMatchMode (whatever)
#IfWin.., (a window title)
 hotkey1::
#IfWin.., (another window title)
 hotkey2::

or

SetTitleMatchMode (whatever)
Hotkey, IfWin.., (a window title)
 Hotkey, hotkey1, Label1
Hotkey, IfWin.., (another window title)
 Hotkey, hotkey2, Label2


But this won't
Code:
SetTitleMatchMode (whatever 1)
#IfWin.., (a window title)
 hotkey1::

SetTitleMatchMode (whatever 2)   ;can only have ONE of these in main thread
#IfWin.., (another window title)
 hotkey2::

or

SetTitleMatchMode (whatever 1)
Hotkey, IfWin.., (a window title)
 Hotkey, hotkey1, Label1

SetTitleMatchMode (whatever 2)   ;only ONE allowed
Hotkey, IfWin.., (another window title)
 Hotkey, hotkey2, Label2


My idea (#SetTitleMatchMode)...
Still wouldn't work
Code:
SetTitleMatchMode (whatever 1)
Hotkey, IfWin.., (a window title)
 Hotkey, hotkey1, Label1

SetTitleMatchMode (whatever 2)   ;only ONE allowed
Hotkey, IfWin.., (another window title)
 Hotkey, hotkey2, Label2
But this WOULD work ...
Code:
#SetTitleMatchMode (whatever 1)
#IfWin.., (a window title)
 hotkey1::

#SetTitleMatchMode (whatever 2)   ;can have MORE THAN ONE these in main thread
#IfWin.., (another window title)
 hotkey2::


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 27th, 2009, 7:50 am 
Offline

Joined: August 24th, 2005, 5:29 pm
Posts: 549
Location: Berlin / Germany
This WILL work:
Code:
; ##############################################################################
#NoEnv
SetTitleMatchmode, 2
; ...
; ...
; ...
HotKey, IfWinActive, ^must be exactly another title$     ; MatchMode 3
Hotkey, a, Hotkey
Hotkey, IfWinActive
; ...
; ...
; ...
Gui, Margin, 0, 0
Gui, Font, s16
Gui, Add, Text, w400 h400 Center 0x200 cNavy vTX
Gui, Show, w400 h400, must be exactly another title
IfWinExist, exactly
   MsgBox, Found Gui window!`nMatchMode : %A_TitleMatchMode%
GuiControl, , TX, Press "a", please.
; ...
; ...
; ...
SetTitleMatchMode, RegEx
Return  ; end of auto-execute section
; ##############################################################################
GuiClose:
ExitApp
Hotkey:
   MsgBox, Title matched "must be exactly another title"`nMatchMode : %A_TitleMatchMode%
   Gui, Show, , title must start with ...
Return
#IfWinActive ^title must start with       ; MatchMode 1
a::
   MsgBox, Title matched "title must start with"`nMatchMode : %A_TitleMatchMode%
   Gui, Show, , ... title must contain ...
Return
#IfWinActive title must contain           ; MatchMode 2
a::
   MsgBox, Title matched "title must contain"`nMatchMode : %A_TitleMatchMode%
   Gui, Show, , title must be exactly
Return
#IfWinActive ^title must be exactly$      ; MatchMode 3
a::
   MsgBox, Title matched "title must be exactly"`nMatchMode : %A_TitleMatchMode%
   Gui, Show, , must be exactly another title
Return
#IfWinActive

_________________
nick :wink:


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 18 posts ]  Go to page 1, 2  Next

All times are UTC [ DST ]


Who is online

Users browsing this forum: Leef_me and 5 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