 |
AutoHotkey Community Let's help each other out
|
| View previous topic :: View next topic |
| Author |
Message |
a_h_k
Joined: 02 Feb 2008 Posts: 626
|
Posted: Tue Nov 17, 2009 9:40 am Post subject: Have #SetTitleMatchMode |
|
|
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 |
|
| Back to top |
|
 |
a_h_k
Joined: 02 Feb 2008 Posts: 626
|
Posted: Tue Nov 17, 2009 1:49 pm Post subject: |
|
|
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 Thu Nov 19, 2009 12:27 pm; edited 1 time in total |
|
| Back to top |
|
 |
Lexikos
Joined: 17 Oct 2006 Posts: 7292 Location: Australia
|
Posted: Thu Nov 19, 2009 11:40 am Post subject: |
|
|
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... |
|
| Back to top |
|
 |
a_h_k
Joined: 02 Feb 2008 Posts: 626
|
Posted: Thu Nov 19, 2009 12:47 pm Post subject: |
|
|
Sorry, that was incorrect
It should be "#IfWin.../Hotkey, IfWin... " (i have made the correction)
So RegEx works with #IfWin.../Hotkey, IfWin... ? |
|
| Back to top |
|
 |
Lexikos
Joined: 17 Oct 2006 Posts: 7292 Location: Australia
|
Posted: Thu Nov 19, 2009 12:52 pm Post subject: |
|
|
| Yes. |
|
| Back to top |
|
 |
a_h_k
Joined: 02 Feb 2008 Posts: 626
|
Posted: Thu Nov 19, 2009 1:04 pm Post subject: |
|
|
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, ...
... |
??? |
|
| Back to top |
|
 |
Lexikos
Joined: 17 Oct 2006 Posts: 7292 Location: Australia
|
Posted: Fri Nov 20, 2009 8:31 am Post subject: |
|
|
| Code: | SetTitleMatchMode, RegEx
Hotkey, IfWinActive, .*Mozilla Firefox
Hotkey, RCtrl, Test
return
Test:
MsgBox
return |
Works for me. |
|
| Back to top |
|
 |
a_h_k
Joined: 02 Feb 2008 Posts: 626
|
Posted: Fri Nov 20, 2009 1:08 pm Post subject: |
|
|
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" |
|
|
| Back to top |
|
 |
Lexikos
Joined: 17 Oct 2006 Posts: 7292 Location: Australia
|
Posted: Fri Nov 20, 2009 1:40 pm Post subject: |
|
|
| 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). |
|
| Back to top |
|
 |
a_h_k
Joined: 02 Feb 2008 Posts: 626
|
Posted: Sat Nov 21, 2009 7:02 am Post subject: |
|
|
| 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 Sat Nov 28, 2009 6:22 am; edited 1 time in total |
|
| Back to top |
|
 |
nick
Joined: 24 Aug 2005 Posts: 549 Location: Berlin / Germany
|
Posted: Thu Nov 26, 2009 6:02 am Post subject: |
|
|
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  |
|
| Back to top |
|
 |
a_h_k
Joined: 02 Feb 2008 Posts: 626
|
Posted: Thu Nov 26, 2009 1:28 pm Post subject: |
|
|
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 |
|
| Back to top |
|
 |
nick
Joined: 24 Aug 2005 Posts: 549 Location: Berlin / Germany
|
Posted: Thu Nov 26, 2009 2:28 pm Post subject: |
|
|
| 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  |
|
| Back to top |
|
 |
a_h_k
Joined: 02 Feb 2008 Posts: 626
|
Posted: Fri Nov 27, 2009 5:55 am Post subject: |
|
|
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:: |
|
|
| Back to top |
|
 |
nick
Joined: 24 Aug 2005 Posts: 549 Location: Berlin / Germany
|
Posted: Fri Nov 27, 2009 6:50 am Post subject: |
|
|
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  |
|
| 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
|