Jump to content

Trying to send a hotkey


Recommended Posts

Hi, I am using autoit3 for the first time, and I am trying to write a script that will send a CTRL + M hotkey to an iTunes window. I'm not sure what I am doing wrong but here is the code:

Func dbg($msg)
    DllCall("kernel32.dll", "none", "OutputDebugString", "str", $msg)
EndFunc

AutoItSetOption ("WinTitleMatchMode", 4)
If WinExists( "[CLASS:iTunes; Title:iTunes]" ) Then
    $pos = WinGetPos( "[Class:iTunes; Title:iTunes]" )
    dbg("iTunes found using class and title. Height is: " & $pos[3])
    If $pos[3] < 100 Then
        dbg("Found iTunes mini player. Enlarging...")
        $focusid = ControlGetFocus ("[Class:iTunes; Title:iTunes]")
        dbg("ControlRef # is (1 mean broken): " & $focusid & @error)
        ControlFocus ( "", "", $focusid )
        dbg("Focus acquired? " & @error)
        ControlSend ( "iTunes", "", "", "{LCRTL}m" )
        dbg("Key stroke sent? " & @error)
        $pos = WinGetPos ( "[Class:iTunes; Title:iTunes]" )
        dbg("New height is: " & $pos[3])
    Else
        
        dbg("Full-sized iTunes found")
    EndIf
EndIf
Link to comment
Share on other sites

According to the debugger it works until it gets to where I start using controls, but nothing happens because the only real visible changes are done after that point.

I don't think your Send key pattern is what you wanted. This should work:

Opt("WinTitleMatchMode", 4)

If WinExists("[CLASS:iTunes; Title:iTunes]") Then
    $hITunes = WinGetHandle("[CLASS:iTunes; Title:iTunes]")
    $pos = WinGetPos($hITunes)
    If $pos[3] < 100 Then
        WinActivate($hITunes)
        WinWaitActive($hITunes)
        ControlSend ($hITunes, "", "", "^m" )
        ; ---------------------------------------------------------
        ; Alternate method if it must be LCTRL:
        ;   ControlSend ($hITunes, "", "", "{LCTRL down}m{LCTRL up}" )
        ; ---------------------------------------------------------
    EndIf
EndIf

First it gets and uses the window handle for operation. Then it sends "^m" vice "{LCTRL}m", which is Ctrl-m. If it really MUST be the left control key, then the alternate is included in a comment: "{LCTRL down}m{LCTRL up}"

:)

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
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...