Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I'm new to AHK scripts and I would like to be able to press #n (windows key + n) and trigger a series of keyboard combinations (shift + end, alt + tab, ^T, ^V, enter, tab, enter) each time I press that.

This is as far as I've gotten but no matter how much I read online about it, I feel i need some extra help (samples out there are usually super complex).

(Edited final code that worked for me thanks to Robert Ilbrink, a slight modification of his proposal)

#SingleInstance Force
#installKeybdHook
#Persistent
SetTitleMatchMode, 2
#IfWinActive, Word ; #n will only trigger when working inside Word.
#n::  ; [Win]+n trigger key
    ClipBoard =  ; Clear ClipBoard
    Send, +{End} ; [Shift]+[End]
    Send, ^c  ; Store selected text in ClipBoard
    Sleep, 100 ; ClipWait seems unreliable
    WinActivate, ahk_class Chrome_WidgetWin_1
    Send, ^t ; In my Chrome setup I immediately get a Google search page.
    Send, ^v;
    Send, {Enter};
    Sleep, 1000 ;
    Send, {Tab}{Enter};
    ;SoundBeep, 500, 500
Return
#IfWinActive
share|improve this question
    
Lolo, What is it that you want? Create a new tab in chrome? I am not sure why you send multiple LShift and RCtrl commands. You try to put focus on a new Chrome tab, but how can you be sure this new Chrome tab is there (you could run #n inside Notepad and nothing useful would happen).. So what are you after? –  Robert Ilbrink Mar 29 '13 at 11:50
    
OK, I'll clarify: I'm constantly reviewing some word files. From time to time I need to copy a line (shift + end), alt tab (I will always have chrome next in order to word), open a new tab, paste the copied string, search in google, tab + enter to open first result. I have RSI and automating this process I do literally hundreds of times a day will help my condition. –  Lolo Jones Mar 29 '13 at 11:53

1 Answer 1

up vote 0 down vote accepted

Lolo, I'll give it a try, but I am still puzzled.

#SingleInstance Force
#installKeybdHook
#Persistent
SetTitleMatchMode, 2
#IfWinActive, Word ; #n will only trigger when working inside Word.
#n::  ; [Win]+n trigger key
    ClipBoard =  ; Clear ClipBoard
    Send, +{End} ; [Shift]+[End]
    Send, ^c  ; Store selected text in ClipBoard
    Sleep, 100 ; ClipWait seems unreliable
    WinActivate, ahk_class Chrome_WidgetWin_1
    Send, ^t ; In my Chrome setup I immediately get a Google search page.
    WinWaitActive, Google - Google Chrome ; Wait for Google search Page
    Send, %ClipBoard%{Enter}  ; Send ClipBoard Text to Google
    WinWaitActive, %ClipBoard%  ; Wait for window title with search string
    Send, {Tab}{Enter}
    SoundBeep, 500, 500
Return
#IfWinActive

Added the Tab+Enter combo. This does NOT work on my machine, since Tab jumps to the Black Google+ menu bar....

share|improve this answer
    
This does not trigger on a keypress. –  Bob Mar 29 '13 at 12:09
    
I am still writing, not finished yet.... –  Robert Ilbrink Mar 29 '13 at 12:10
    
The key combo consists of pressing tab and then enter. Tab selects the first result, enter accesses it (all of this once the google search has been conducted). –  Lolo Jones Mar 29 '13 at 12:16
    
Somehow it seems the keystroke only works after running the AHK, not afterwards. E.g. I run the AHK, press the keystroke and it only works once. After that I have to run the AHK again. Also, it focuses on the chrome address bar but it doesn't paste what was copied. Tried adding a "Send, ^v" but it doesn't work (if I manually press ^v the right clipboard is pasted -so it's not a problem about copying) –  Lolo Jones Mar 29 '13 at 12:23
    
Is ahk still active in the system tray? Remember that [Win]+n ONLY triggers when inside Word! –  Robert Ilbrink Mar 29 '13 at 12:25

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.