Forethinker
Forethinker

Reputation: 3778

SendInput without a binding keyword

I am trying to send input to VMWare Player when I switch to it. This is so that do not have press Ctrl-g and make the VMWare grab my input. The following is the script I came up with, but it does not do anything. What is it that missed?

#IfWinActive ahk_class VMPlayerFrame
{
    SendInput, {Ctrl down}g{Ctrl up}
}                                                                               return

Upvotes: 0

Views: 459

Answers (1)

Robert Ilbrink
Robert Ilbrink

Reputation: 7963

You can use #IfWinActive to change hotkeys or hotstrings, but not to create scripts.

You need to detect the window change, and act on that.

#SingleInstance
#installKeybdHook
#Persistent

Gui +LastFound 
hWnd := WinExist()
DllCall( "RegisterShellHookWindow", UInt,Hwnd )
MsgNum := DllCall( "RegisterWindowMessage", Str,"SHELLHOOK" )
OnMessage( MsgNum, "ShellMessage" )
Return

ShellMessage( wParam )
{
    If (wParam = 4 or wParam = 32772) ; Without VMware Player running: wParam = 4, with VMware Player running: wParam = 32772
    {        
        IfWinActive ahk_class VMPlayerFrame
        {
            SendInput, {Ctrl down}g{Ctrl up}
        }
    }
}
Return

; Hotkey {Win}+g launches Chrome
#g::Run "C:\Users\%A_Username%\AppData\Local\Google\Chrome\Application\chrome.exe"

; Hotkeys {Ctrl}+Nr gives you fractures
^2::
    Send, ½
    TrayTip, For 2 Squared,press Ctrl + Shift 2,1,1
Return

^3::
    Send, ¾
    TrayTip, For 3 Cubed,press Ctrl + Shift 3,1,1
Return

^4::Send, ¼

; HotKeys {Shift}+{Ctrl}+Nr gives you the power
+^0::Send, °
+^1::Send, ¹
+^2::Send, ² ; Shift Control 2@
+^3::Send, ³ ; Shift Control 3#

; Hotstrings mvge, mvgd or mvgf will give you my salutations in various languages.
:*:mvge::Regards,{Enter}{Enter}Robert Ilbrink
:*:mvgd::Mit freundlichen Grüßen,{Enter}{Enter}Robert Ilbrink
:*:mvgf::Salutions,{Enter}{Enter}Robert Ilbrink

Upvotes: 1

Related Questions