tecc Posted August 26, 2018 Posted August 26, 2018 I plan on using F2 - F11 as hotkeys to switch between open programs which works fine. However, I use Outlook Mail and Outlook Calendar with different users which results in similar window titles: Kalender - user@firma.de - Outlook Posteingang - user@firma.de - Outlook So if I match for " - Outlook", both windows would qualify and since I might be in any folder in Outlook Mail, I can't match "Posteingang" (Inbox) either. So I think, I should use a Regex to match " - Outlook" only if the Windows Title does not also include "Kalender". What regex do I use and how do I implement it in AutoIt? Thx!
Jury Posted August 26, 2018 Posted August 26, 2018 If StringInStr($title, "Kalender") = 0 Then ConsoleWrite("Kalender not found" & @CRLF) EndIf
jchd Posted August 26, 2018 Posted August 26, 2018 Local $s1 = "Kalender - user@firma.de - Outlook" Local $s2 = "Posteingang - user@firma.de - Outlook" ConsoleWrite(StringRegExp($s1, "(?i)(?<!^kalender) - .* - outlook") & @LF) ConsoleWrite(StringRegExp($s2, "(?i)(?<!^kalender) - .* - outlook") & @LF) This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe hereRegExp tutorial: enough to get startedPCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta. SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)
tecc Posted August 26, 2018 Author Posted August 26, 2018 Sorry guys, I've been using this to open the Outlook Calendar #include <MsgBoxConstants.au3> HotKeySet("{F2}", "_programm2") HotKeySet("{F3}", "_programm3") Func _programm2() if ProcessExists("outlook.exe") then Opt("WinTitleMatchMode", 2) WinActivate("Kalender - ") EndIf EndFunc but I have no idea how to adapt your suggestions into the WinActivate line when I want to match " - Outlook" but at the same time not match "Kalender". Something like this? Func _programm3() if ProcessExists("outlook.exe") then Opt("WinTitleMatchMode", 2) WinActivate("[REGEXPTITLE:(?<!^kalender) - .* - outlook")]") EndIf EndFunc
jchd Posted August 26, 2018 Posted August 26, 2018 Did you try it? Func _programm3() If ProcessExists("outlook.exe") Then Opt("WinTitleMatchMode", -2) ; we need case-insensitive mode WinActivate("[REGEXPTITLE:(?<!^kalender) - .* - outlook]") ; removed spurious characters EndIf EndFunc This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe hereRegExp tutorial: enough to get startedPCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta. SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)
caramen Posted August 27, 2018 Posted August 27, 2018 (edited) Why not use the full name of the windows title ? * I wonder why you dont do that since it s the most simple way to do that ? Opt("WinTitleMatchMode", 3) ;WinTitleMatchMode Alters the method that is used to match window titles during search operations. ;1 = (default) Match the title from the start ;2 = Match any substring in the title ;3 = Exact title match ;4 = Advanced mode (retained for backwards compatibility only - see Window Titles & Text (Advanced)) ;-1 to -4 = Case insensitive match according to the other type of match. $Title = WinGetTitle ( "[active]" ) If $Title = "Kalender - user@firma.de - Outlook" Then ElseIF $Title = "Posteingang - user@firma.de - Outlook" Then EndIf Edited August 27, 2018 by caramen My video tutorials : ( In construction ) || My Discord : https://discord.gg/S9AnwHw How to Ask Help || UIAutomation From Junkew || WebDriver From Danp2 || And Water's UDFs in the Quote Spoiler Water's UDFs:Active Directory (NEW 2018-10-19 - Version 1.4.10.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX (2018-10-31 - Version 1.3.4.1) - Download - General Help & Support - Example Scripts - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsPowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & SupportExcel - Example Scripts - WikiWord - Wiki Tutorials:ADO - Wiki
junkew Posted August 27, 2018 Posted August 27, 2018 Winlist will give you two hwnd. Store this at start of your script in variables and then use these to activate right window. FAQ 31 How to click some elements, FAQ 40 Test automation with AutoIt, Multithreading CLR .NET Powershell CMDLets
tecc Posted August 27, 2018 Author Posted August 27, 2018 8 hours ago, caramen said: Why not use the full name of the windows title ? I wonder why you dont do that since it s the most simple way to do that ? Because, as I wrote above, it can be any one of 3 different user names in that title as well as more than 10 folder names. That's a lot of combinations. So the easiest way would be to filter for " - Outlook" without "Kalender" in it. Unfortunately Jchd's Regex from above does not work.
jchd Posted August 27, 2018 Posted August 27, 2018 That's strange since the regex works like a charm. Did you try my last snippet? This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe hereRegExp tutorial: enough to get startedPCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta. SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)
caramen Posted August 28, 2018 Posted August 28, 2018 (edited) If you are using Opt 2 with the match title, if you got only one window at time you should then use only "- Outlook" and that should be enouth...If not then just use the WinGetTitle [active] to check if the value is correct first. Edited August 28, 2018 by caramen My video tutorials : ( In construction ) || My Discord : https://discord.gg/S9AnwHw How to Ask Help || UIAutomation From Junkew || WebDriver From Danp2 || And Water's UDFs in the Quote Spoiler Water's UDFs:Active Directory (NEW 2018-10-19 - Version 1.4.10.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX (2018-10-31 - Version 1.3.4.1) - Download - General Help & Support - Example Scripts - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsPowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & SupportExcel - Example Scripts - WikiWord - Wiki Tutorials:ADO - Wiki
badcoder123 Posted August 28, 2018 Posted August 28, 2018 (edited) #include <Array.au3> Local $aHWNDList, $aTitle = "TITLE" $aHWNDList = WinList("[REGEXPTITLE:(?i)(.*" & $aTitle & ".*)]") _ArrayDisplay($aHWNDList) Edited August 28, 2018 by badcoder123
tecc Posted August 28, 2018 Author Posted August 28, 2018 19 hours ago, caramen said: If you are using Opt 2 with the match title, if you got only one window at time you should then use only "- Outlook" and that should be enouth...If not then just use the WinGetTitle [active] to check if the value is correct first. How do you mean? Even with one window, the window title can read Kalender - user1@company.com - outlook Kalender - user2@company.com - outlook Kalender - user3@company.com - outlook inbox - user1@company.com - outlook inbox - user2@company.com - outlook inbox - user3@company.com - outlook sent - user1@company.com - outlook sent - user2@company.com - outlook sent - user3@company.com - outlook waiting - user1@company.com - outlook waiting - user2@company.com - outlook waiting - user3@company.com - outlook etc. 21 hours ago, jchd said: That's strange since the regex works like a charm. Did you try my last snippet? Yes, I have. I even tried it on regex101.com with the test string 'Kalender - user1@firma.de - outlook' which still gets selected from the first character after the word 'kalender'. What I expected from the regex was to not select any part of it as long as the title contains the word 'kalender'.
junkew Posted August 28, 2018 Posted August 28, 2018 Why are you looking to solve your problem with a regex? Your requirements seems to be changing with initial start 1 user 2 windows open (1 calendar and 1 inbox window) Now n calendar windows and m inbox windows from x users? unclear if now n,m,x are equal Did you try an approach with winlist? Here some sample for testing expandcollapse popup#include <Array.au3> local $strWindows="Kalender - user1@company.com - outlook;" $strWindows=$strWindows & "Kalender - user2@company.com - outlook;" $strWindows=$strWindows & "Kalender - user3@company.com - outlook;" $strWindows=$strWindows & "inbox - user1@company.com - outlook;" $strWindows=$strWindows & "inbox - user2@company.com - outlook;" $strWindows=$strWindows & "inbox - user3@company.com - outlook;" $strWindows=$strWindows & "sent - user1@company.com - outlook;" $strWindows=$strWindows & "sent - user2@company.com - outlook;" $strWindows=$strWindows & "sent - user3@company.com - outlook;" $strWindows=$strWindows & "waiting - user1@company.com - outlook;" $strWindows=$strWindows & "waiting - user2@company.com - outlook;" $strWindows=$strWindows & "waiting - user3@company.com - outlook;" consolewrite($strWindows & @CRLF) Local $aHWNDList Local $aTitle = "kalender" Local $pattern= $aTitle $aHWNDList = stringsplit($strWindows,";") ;~ WinList("[REGEXPTITLE:(?i)(.*" & $aTitle & ".*)]") ;~ _ArrayDisplay($aHWNDList) consolewrite("Test 1" & @CRLF) consolewrite(getTheFirstWinTitle($pattern, true) & @CRLF) consolewrite("Test 2" & @CRLF) consolewrite(getTheFirstWinTitle($pattern, false) & @CRLF) ;~ Helper function func getTheFirstWinTitle($pattern, $winCalendar) for $i=1 to ubound($aHwndList)-1 ;~ if stringregexp($aHwndList,$pattern,0) Then if ($winCalendar=true) Then if (stringinstr($aHWNDList[$i],$pattern) > 0) then consolewrite("HOORAY: We have a calendar " & $aHWNDList[$i] & @CRLF) $strFoundTitle=$aHWNDList[$i] exitloop endif EndIf if ($winCalendar=false) Then if (stringinstr($aHWNDList[$i],$pattern) = 0) then consolewrite("HOORAY: Its NOT a calendar " & $aHWNDList[$i] & @CRLF) $strFoundTitle=$aHWNDList[$i] exitloop endif EndIf Next return $strFoundTitle EndFunc FAQ 31 How to click some elements, FAQ 40 Test automation with AutoIt, Multithreading CLR .NET Powershell CMDLets
jchd Posted August 28, 2018 Posted August 28, 2018 @tecc Strange as I can check it works in regex101 (as well as in AutoIt): https://regex101.com/r/ECKFJC/2 This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe hereRegExp tutorial: enough to get startedPCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta. SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)
tecc Posted September 2, 2018 Author Posted September 2, 2018 @junkew I may not have worded it very good but right from the beginning I said that was using different users as well as pretty much any folder in Outlook mail. Which is the reason why I think regex is the way to go here. On 29.8.2018 at 1:34 AM, jchd said: @tecc Strange as I can check it works in regex101 (as well as in AutoIt): https://regex101.com/r/ECKFJC/2 Yeah, I've seen this and it looks good. However, when I copy over your code from August 26th and press the corresponding key after executing the script, I don't get Outlook Mail. I do however get Outlook Calendar. So while the regex seems correct, something with the implementation seems to be off (on my system). Also, in the meantime I've been made aware that having programs attached to the taskbar in Windows 10 allows you to start/switch to them using WIN+1 for the first program and so on. Problem here is that if you've opened Outlook Mail, notification and calendar, you'll have to press the number thrice to get to the last window of the programs grouped together. Therefore I'd still like to see your approach work while I'd like to add another wrinkle: my keyboard at work dual uses some of the regular keys as pointless multimedia keys activated by the FN key. Is there a way to use this one as a hotkey? FN+2 could be used to start a program. And what about redesignating the CAPS LOCK key? I've never use it anyway.
jchd Posted September 2, 2018 Posted September 2, 2018 I'm afraid I can't help any more as I don't use Outlook at all. Same about your specific keyboard. This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe hereRegExp tutorial: enough to get startedPCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta. SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)
junkew Posted September 2, 2018 Posted September 2, 2018 (edited) How do you start your programs? How do you want to assign which window to which function key? You start a program and then you have your process and hwnd handle You assign that in an array to your functionkey You use that to activate window based on hwnd. BTW: ^[^(Kalender)].*outlook should come close (maybe leave out the ^ beginning of line marker Edited September 3, 2018 by junkew FAQ 31 How to click some elements, FAQ 40 Test automation with AutoIt, Multithreading CLR .NET Powershell CMDLets
tecc Posted September 6, 2018 Author Posted September 6, 2018 Junkew, I've confirmed your regex to work as well on regex101 but when added to the script, it still only switches to the calendar but never to Outlook mail. I've also tried your hwhandle approach, unfortunately to no avail either. Looks like I'm gonna have to stick to WIN+1 etc. to switch, thanks though.
junkew Posted September 6, 2018 Posted September 6, 2018 Below works fine on my W10 machine with AutoIt Running:(3.3.14.2) (Switching between calculators and windows mail) Could not get Fnn keys working so used ctrl+alt+number (1-5 is calc/Rekenmachine or in your case Kalender, 6-0 is the first not having Kalender) For me still a little unclear what you want (switch between 2 or n windows, (non)hidden windows, opened and closed windows of email) Play with the winlist lines to filter I have on my machine tested with Calc.exe and Windows mail to switch to first match/non matching window You can enhance it to find 2nd, 3rd match based on the $position (which is based on the keynumber) expandcollapse popup#include <WinAPI.au3> #include <Array.au3> Global $g_myIDString="Rekenmachine" ;~ Global $g_myIDString="Kalender" ; Press Esc to terminate script HotKeySet("{ESC}", "HotKeyPressed") HotKeySet("^!1", "HotKeyPressed") HotKeySet("^!2", "HotKeyPressed") HotKeySet("^!3", "HotKeyPressed") HotKeySet("^!4", "HotKeyPressed") HotKeySet("^!5", "HotKeyPressed") HotKeySet("^!6", "HotKeyPressed") HotKeySet("^!7", "HotKeyPressed") HotKeySet("^!8", "HotKeyPressed") HotKeySet("^!9", "HotKeyPressed") HotKeySet("^!0", "HotKeyPressed") While 1 Sleep(100) WEnd Func HotKeyPressed() tooltip("Hotkey" & @hotkeypressed) sleep(500) tooltip("") if stringlen(@hotkeypressed)>2 Then ;~ If stringleft(@HotKeyPressed,2)="{F" Then If stringleft(@HotKeyPressed,2)="^!" Then local $FKeyNumber=int(stringregexpreplace(@hotkeypressed,"(\^)|(!)|({F)|(})","")) if $fKeyNumber=0 then $fKeyNumber=10 if $FKeyNumber <=5 Then myWinActivate($g_myIDString, $FKeyNumber, true) Else myWinActivate($g_myIDString, $FKeyNumber-5, false) EndIf EndIf Else Switch @HotKeyPressed ; The last hotkey pressed. Case "{ESC}" ; String is the {ESC} hotkey. Exit Case "+!d" ; String is the Shift-Alt-d hotkey. MsgBox($MB_SYSTEMMODAL, "", "This is a message.") EndSwitch EndIf EndFunc ;==>HotKeyPressed func myWinActivate($str, $position, $bWordPresent) ;~ Get subset of windows of interest Local $aWinList = WinList("[REGEXPTITLE:((.*Mail)|(.*Rekenmachine))]") ;~ Local $aWinList = WinList("[REGEXPCLASS:((ATH_Note)|(ApplicationFrameWindow))]") ;~ Local $aWinList = WinList("[REGEXPTITLE:.*Outlook.*]") ;~ Local $aWinList = WinList() ;~ _ArrayDisplay($aWinList) ; Loop through the array to match For $i = 1 To $aWinList[0][0] Local $hwnd= $aWinList[$i][1] Local $tClassName=_WinAPI_GetClassName ( $hWnd ) Local $title= $aWinList[$i][0] ;~ For showing some information on what to filter and what not as input for winlist function if (stringinstr("AutoIt v3 GUI,tooltips_class32",$tClassName) <=0) then ;~ if ($title <>"") and (stringinstr("AutoIt v3 GUI,tooltips_class32",$tClassName) <=0) then ;~ if ($title <>"") then consolewrite("Title: " & $title & @TAB & " Handle: " & $aWinList[$i][1] & " Class: " & $tClassName & @CRLF) EndIf If $aWinList[$i][0] <> "" And BitAND(WinGetState($aWinList[$i][1]), 2) Then ;~ Check if the condition is True $bMatchedWindow=-1 if stringinstr($title, $str) > 0 Then $bMatchedWindow=$bWordPresent ? $HWND : -1 Else $bMatchedWindow=$bWordPresent ? -1 : $HWND EndIf ;~ We have a match if $bMatchedWindow <> -1 Then ;~ tooltip("m Title: " & $title & @TAB & " Handle: " & $aWinList[$i][1] & " Class: " & $tClassName & @CRLF) winactivate($hwnd) exitloop EndIf EndIf Next EndFunc FAQ 31 How to click some elements, FAQ 40 Test automation with AutoIt, Multithreading CLR .NET Powershell CMDLets
jchd Posted September 7, 2018 Posted September 7, 2018 On 02/09/2018 at 7:20 PM, junkew said: ^[^(Kalender)].*outlook This doesn't do what you seem to believe it does. In a character class (inside square brackets) parenthesis don't have a special meaning. So what the part in bold of the pattern means is " Match any character not in the string (Kalender) " This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe hereRegExp tutorial: enough to get startedPCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta. SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now