Jump to content

Computer Behaving Oddly After Running Script


eyc
 Share

Recommended Posts

the following code is meant to create a hotkey for starting a new outlook journal entry.

Func startJournal ()

    ControlSend("", "", "", "text", 0)

    Opt("WinTitleMatchMode", 2)     ;1=start, 2=subStr
    If @error Then
        MsgBox (0, "error", "setting win title match mode failed")
        Return
    EndIf
    
    $returnVal = WinActivate("Microsoft Outlook")

    If $returnVal <> 0 Then
        Send("^+j")
        $returnVal = WinWaitActive("Untitled - Journal Entry")
        If $returnVal = 0 Then
            MsgBox (0, "error", "journal entry window never became active")
            Return
        EndIf
        Send("!")
        Send("ht")
    Else
        MsgBox(0, "error", "outlook window not found")
        Return
    EndIf

EndFunc



$returnVal = HotKeySet("^;", "startJournal")
If $returnVal = 0 Then
    MsgBox (0, "error", "couldn't register HotKey")
    Exit
EndIf

while 1
    Sleep(100)
WEnd

this script is causing my keyboard and mouse to stop working properly. the problem doesn't occur every time, but it seems to occur at least once out of ten times.

after running this script and executing the hotkey function, the win key no longer activates the start menu. other funny things happen too. for instance, the escape key brings up the task manager.

i've seen other people post similar experiences, but i haven't seen any solutions. I have to put my computer into standby mode in order to get it back to normal.

does anybody know why this occurs?

my specs:

windows 7

autoIt version 3.3.6.1

ms outlook 2007

Link to comment
Share on other sites

  • Moderators

That's really horrible code. Where did you get it?

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

Hi,

  • When you set a hotkey, AutoIt captures the key-press and does not pass it on to the active application, with one exception: the Lock keys (NumLock, CapsLock, and ScrollLock) still toggle their respective state!

    To Send() a key combination which will trigger a HotKeySet() event, either use ControlSend() or unregister the HotKeySet() event, otherwise, the Send() event may trigger an infinite loop.

    so better use _Ispressed
  • exit or pause your script when you don't need it.
  • Have a look on WinGetState example in the help and modify it that way keys only are send when your outlook is the active window or best way: use controlsend:

    Remarks

    ControlSend works in a similar way to Send but it can send key strokes directly to a window/control, rather than just to the active window.

mfg autoBert

Edited by AutoBert
Link to comment
Share on other sites

  • 2 weeks later...

thanks for the help, autobert. i got my script working by unsetting my hotkey and using the code found at http://www.autoitscript.com/wiki/FAQ#Why_does_the_Ctrl_key_get_stuck_down_after_I_run_my_script.3F

#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



Func startJournal ()

    $returnVal = HotKeySet("^;")
    If $returnVal = 0 Then
        MsgBox (0, "error", "couldn't unregister HotKey")
        Exit
    EndIf

    Opt("WinTitleMatchMode", 2)     ;1=start, 2=subStr
    If @error Then
        MsgBox (0, "error", "setting win title match mode failed")
        Return
    EndIf
    
    $returnVal = WinActivate("Microsoft Outlook")

    If $returnVal <> 0 Then
        _SendEx("^+j")
        $returnVal = WinWaitActive("Untitled - Journal Entry")
        If $returnVal = 0 Then
            MsgBox (0, "error", "journal entry window never became active")
            Return
        EndIf
        _SendEx("!")
        _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;==>startJournal



$returnVal = HotKeySet("^;", "startJournal")
If $returnVal = 0 Then
    MsgBox (0, "error", "couldn't register HotKey")
    Exit
EndIf

while 1
    Sleep(100)
WEnd
Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...