Reputation: 141
I use AutoHotkey for windows. I want to write a script in order to paste (the text I copied earlier) with middle button click of the mouse to searchbar of the program Oxford dictionary on my computer. and also when the the window of the program is closed, after I clicked middle button of the mouse automatically open the window and do the same thing I wanted( paste the copied word into the searchbar of program). I write this code :
MButton::
IfWinExist, Oxford Advanced Learner's Dictionary
{
WinActivate
Click, 182, 133, 2
Send, ^a{Delete}
sleep, 100
Send, ^v{Enter}
}
else
{
Run, "E:\dictionary oxford\OALD9.exe"
WinActivate, Oxford Advanced Learner's Dictionary
sleep, 500
Click, 182, 133, 2
Send, ^a{Delete}
sleep, 100
Send, ^v{Enter}
}
return
When I run the code, it just do the first task I wanted. It paste into the search bar of the Oxford Dictionary when it is open. But when it is closed, after I click middle button of the mouse it just open the program and doesn't paste the word into the searchbar.
Upvotes: 0
Views: 259
Reputation: 26
WinWait is your friend. Documentation
MButton::
IfWinExist, Oxford Advanced Learner's Dictionary
{
WinActivate
Click, 182, 133, 2
Send, ^a{Delete}
Sleep, 100
Send, ^v{Enter}
}
else
{
Run, "E:\dictionary oxford\OALD9.exe"
WinWait, Oxford Advanced Learner's Dictionary,,4
WinActivate, Oxford Advanced Learner's Dictionary
Sleep, 500
Click, 182, 133, 2
Send, ^a{Delete}
Sleep, 100
Send, ^v{Enter}
}
return
Edit: You might want to consider RunWait, also. Documentation
Upvotes: 1