Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

Switching Active Windows and Sending a Keystroke


Best Answer robert_ilbrink , 03 May 2013 - 11:17 AM

Go to the full post »


  • Please log in to reply
3 replies to this topic
togashi
  • Members
  • 2 posts
  • Last active: Nov 08 2013 10:07 PM
  • Joined: 02 May 2013

Probably a very simle question, but I'm having trouble getting my script to switch windows and then enter a keystroke. I need to go from Program 2 as active to Program 1, send an F4 keystroke, then return to Program 2.

F9::
IfWinExist Program 1
{
    WinActivate
    Send, F4
}
Keywait, F9
IfWinExist Program 2
{
    WinActivate
}
return

Right now, it switches windows but doesn't execute the F4. I am completely new to AHK and apologize for the basic question, but I've been trying to figure this out for over an hour and just am getting frustrated.



Alpha Bravo
  • Members
  • 1687 posts
  • Last active: Nov 07 2015 03:06 PM
  • Joined: 01 Sep 2011

Hello togashi, welcome to the forum

you may need WinWaitActive

and the right syntax is

send, {F4}


robert_ilbrink
  • Members
  • 561 posts
  • Last active: Mar 10 2015 08:36 PM
  • Joined: 05 May 2012
✓  Best Answer

As Alpha Bravo said, use {F4}, but You could also put the F9 hotkey inside a #IfWinActive. This way the F9 key only executes your script when Program 2 is active.

#IfWinActive, Program 2
F9::
IfWinExist Program 1
{
    WinActivate
    Sleep, 100 ; just to be sure
    Send, {F4}
}
Keywait, F9
IfWinExist Program 2
{
    WinActivate
}
return
#IfWinActive


togashi
  • Members
  • 2 posts
  • Last active: Nov 08 2013 10:07 PM
  • Joined: 02 May 2013

Much appreciated guys, makes perfect sense now.