1

I use autohotkey to perform a ctrl+home combo when I press my middle mouse button, with the result of jumping to the top of the webpage I'm on. This, however, breaks down if the cursor is inside a text input box, since ctrl+home in this case merely takes the cursor to the beginning of the input box.

Performing a tab before the ctrl+home can work sometimes, but not always, since the cursor could simply move to another input box. Pressing alt removes the cursor from the input box, but afterwards the ctrl+home won't work.

My goal is to be able to reliably jump to the top of any webpage.

My script at the moment is:

MButton::
SendInput ^{home}
return
;
7
  • Please always provide the code you are experimenting with.
    – vasili111
    Aug 6, 2014 at 17:27
  • I've edited the code in, though I didn't think there would be need for code because what I'm asking about should be accomplish-able with only a keyboard and no code. Aug 6, 2014 at 21:10
  • Can you incorporate in the script additional shortcut before the CTRL+Home? I think if you type in CTRL+F first, then Hit Escape and then hit CTRL+Home it will work every time. I've tested this on Firefox.
    – mnmnc
    Aug 6, 2014 at 21:14
  • Is there a way to execute Javascript from a shortcut? Then it would be easy to execute "document.activeElement.blur();"
    – Marcelo
    Aug 6, 2014 at 21:56
  • @mnmnc: I don't have autohotkey, but trying your (Ctrl+F), (Esc), (Ctrl+Home) suggestion in Firefox 31.0 on this very page (i.e., Super User), I get the cursor staying in the text input box. Aug 6, 2014 at 22:36

2 Answers 2

1

@Marcelo gave me the idea of using JavaScript. Earlier I had thought of this, but it didn't seem feasible to do with hotkeys. Then I remembered the JavaScript: pseudo-protocol, and came up with the following code that works reliably:

MButton::
SendInput ^{l}
Sleep 1
SendInput {Raw}javascript:document.activeElement.blur();
Sleep 1
SendInput {Enter}
Sleep 1
SendInput ^{home}
return
;

The code first uses CTRL+l to jump to the address bar, inputs the JavaScript there (Chrome doesn't let pasting javascript: in the address bar, it has to be done as raw input). Enter is pressed to execute the code, in which case a simple Ctrl+Home works to jump to the top.

The Sleep commands are necessary after key combos, otherwise input can get garbled.

While this works reliably (and thus answers my question), it is slow and a little scary, as any issue with the script input can cause the browser to interpret the code as a search query, which will cause the loss of the page's contents.

Instead I am going to use @crazypotato's idea of using page-up, albeit with a sensible number of key presses:

MButton::
SendInput {PgUp 5}
return
;

This works in my case pretty well as the pages I deal with (that necessitated this solution in the first place) are all the same height.

0
!MButton:: ; ALT + Middle Mouse Button
SendInput {PgUp 200} ;press Page-up key 200 times

Some more hackish(not recommended) solutions:

!MButton:: ; ALT + Middle Mouse Button
SendInput {F5} ;easy reload page for remove focus but its save current scroll
Sleep, 1000 ; wait for page loading
SendInput {HOME} ;go home

You need move cursor to empty space on page before press ALT + Middle Mouse Button:

!MButton:: ; ALT + Middle Mouse Button
MouseClick,left ; click on empty space on page with current mouse coord
SendInput {HOME} ;go home u drunk

Update:

Found key for back to top page even if input field focused, but work only with some browsers(dont work in Firefox). Ctrl+Alt+Home

MButton::
SendInput ^!{HOME}
3
  • 1
    But if the user has entered something into the text input box(es), your (F5) solution risks discarding his input. Aug 6, 2014 at 22:39
  • Thats why it hackish. All 3 solutions can fail, but first solution cant fail horribly. Normally better install extension for browser. Firefox extension. Chrome extension. Aug 6, 2014 at 22:57
  • @crazypotato I ended up using your page-up solution in my case, even though it doesn't exactly answer the question (no loss of focus). Thanks! Aug 7, 2014 at 3:05

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .