eyc Posted April 14, 2011 Posted April 14, 2011 I found that WinActivate doesn't activate windows sometimes. I'm not sure why. Has anybody else run across this issue? 8/10 times, WinActivate works, but sometimes it won't activate the window. I don't get any error messages either. The following is my code: expandcollapse popup#include "myFunctions.au3" Func startJournal () $returnVal = HotKeySet("^;") If $returnVal = 0 Then MsgBox (0, "error", "couldn't unregister HotKey") Exit EndIf ; MsgBox(0, "status", "entering startJournal function") Opt("WinTitleMatchMode", 2) ;1=start, 2=subStr If @error Then MsgBox (0, "error", "setting win title match mode failed") Return EndIf ; $returnVal = WinActivate("[CLASS:rctrl_renwnd32]") $returnVal = WinActivate("Microsoft Outlook") MsgBox(0, "status", "after activating outlook window") If $returnVal <> 0 Then ; MsgBox(0, "status", "creating new journal item") _SendEx("^+j") $returnVal = WinWaitActive("Untitled - Journal Entry") If $returnVal = 0 Then MsgBox (0, "error", "journal entry window never became active") Return EndIf _SendEx("!ht") Else MsgBox(0, "error", "outlook window not found") Return EndIf $returnVal = HotKeySet("^;", "startJournal") If $returnVal = 0 Then MsgBox (0, "error", "couldn't register HotKey") Exit EndIf EndFunc $returnVal = HotKeySet("^;", "startJournal") If $returnVal = 0 Then MsgBox (0, "error", "couldn't register HotKey") Exit EndIf while 1 Sleep(100) WEnd myFunctions.au3: #include < Misc.au3 > ;Send the string $ss after the Shift Alt and Ctrl keys are released. Optionally give a warning after 1 sec if any of those keys still down. ;Requires misc.au3 to be included in the script for the _IsPressed function. Func _SendEx($ss) Local $iT = TimerInit() While _IsPressed("10") Or _IsPressed("11") Or _IsPressed("12") If TimerDiff($iT) > 1000 Then If _IsPressed("10") Then MsgBox(262144, "Warning", "shift key is stuck") EndIf If _IsPressed("11") Then MsgBox(262144, "Warning", "control key is stuck") EndIf If _IsPressed("12") Then MsgBox(262144, "Warning", "alt key is stuck") EndIf ControlSend("", "", "", "text", 0) EndIf Sleep(50) WEnd Send($ss) EndFunc;==>_SendEx ; Activates window and exits if window doesn't exist ; Func WinActivateE ($title) ;IsString $title $returnVal = WinActivate($title) If $returnVal = 0 Then MsgBox(0, "error", "window not found") Exit EndIf EndFunc
JScript Posted April 15, 2011 Posted April 15, 2011 (edited) Try this: expandcollapse popup#include < Misc.au3 > Opt("WinTitleMatchMode", 2); Failure will occur if the parameters are invalid (such as an option that doesn't exist). HotKeySet("^;", "_StartJournal") Func _StartJournal() ;MsgBox(0, "status", "entering _StartJournal function") ;If WinActivate("[CLASS:rctrl_renwnd32]") Then If WinActivate("Microsoft Outlook") Then ;MsgBox(0, "status", "creating new journal item") _SendEx("^+j") If Not WinWaitActive("Untitled - Journal Entry") Then MsgBox(0, "error", "journal entry window never became active") Return EndIf _SendEx("!ht") Else MsgBox(0, "error", "outlook window not found") Return EndIf EndFunc ;==>_StartJournal While 1 Sleep(100) WEnd ;Send the string $ss after the Shift Alt and Ctrl keys are released. Optionally give a warning after 1 sec if any of those keys still down. ;Requires misc.au3 to be included in the script for the _IsPressed function. Func _SendEx($ss) Local $iT = TimerInit() While _IsPressed("10") Or _IsPressed("11") Or _IsPressed("12") Sleep(50) If TimerDiff($iT) < 1000 Then ContinueLoop If _IsPressed("10") Then MsgBox(262144, "Warning", "shift key is stuck") If _IsPressed("11") Then MsgBox(262144, "Warning", "control key is stuck") If _IsPressed("12") Then MsgBox(262144, "Warning", "alt key is stuck") ControlSend("", "", "", "text", 0) ExitLoop WEnd Send($ss) EndFunc ;==>_SendEx ; NO REFERENCE FOR THIS... ; Activates window and exits if window doesn't exist Func WinActivateE($title) If Not WinActivate($title) Then MsgBox(0, "error", "window not found") Exit EndIf EndFunc ;==>WinActivateE Edited April 15, 2011 by jscript http://forum.autoitbrasil.com/ (AutoIt v3 Brazil!!!) Somewhere Out ThereJames Ingram Download Dropbox - Simplify your life!Your virtual HD wherever you go, anywhere!
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