Page 1 of 1

close tab with RCtrl

Posted: 25 May 2015, 13:12
by usser
hello!

can you tell me please a script that will close the current tab in Firefox, with RCtrl?

thanks!

Re: close tab with RCtrl

Posted: 25 May 2015, 19:44
by Randy31416
This closes the active tab on my Firefox (ver 33.0.2) by sending the standard close-tab shorkcut (Control+w).

Code: Select all

#IfWinActive, ahk_class MozillaWindowClass ahk_exe firefox.exe
RControl::SendInput, ^w
Possibly Mozilla uses MozillaWindowClass windows elsewhere, and that is why I added the ahk_exe condition to the #IfWinActive. A word of caution, though: lots of shortcut keys involve the control key, and my hands want to type the RControl automatically for many of them, so I am putting tabs in peril every time I hit RControl unless I continue and hit some other key while the control key is still held.

Re: close tab with RCtrl

Posted: 01 Jun 2015, 14:18
by usser
thanks it works very well, I tested it for few days

by the way, can you add to it please the functionality of keyboard arrows left/right to focus the left/right to the active, tab?
but it shouldn't work when the cursor is inside a text box and I want to navigate through the text there!

Re: close tab with RCtrl

Posted: 01 Jun 2015, 16:12
by Nextron
Making the tabs switch using the arrow keys wouldn't be hard, by just sending a ^{tab} or ^+{tab}. But making it conditional by determining if a textbox has focus would be more of a challenge as Firefox doesn't behave as most other applications and its window is basically a black box.

Re: close tab with RCtrl

Posted: 01 Jun 2015, 16:16
by usser
maybe make it work only when there is a blinking vertical line? or the focus is on text box?
or if nothing can be done, then eventually when the cursor is IBeam maybe?

Re: close tab with RCtrl

Posted: 02 Jun 2015, 20:18
by Randy31416
Nextron is correct in that what goes on in the Firefox screen is essentially opaque and unpararsable, except to Firefox. I might suggest (although again I thing RControl by itself is a dangerous thing as I said in the second post) that you use RControl plus a left or right arrow to do the switching of the tabs. After all, RControl is right next to the arrrows on the standard keyboard layout, so it is an easy pair to type. And if you are using RControl by itself to manipulate tabs, your fingers are already there. If you like this, then the following should work (it does on my machine), sending the standard Firefox shortcuts Ctrl+PgUp and Ctrl+PgDn to move the focus tab left and right.

Code: Select all

#IfWinActive, ahk_class MozillaWindowClass ahk_exe firefox.exe
>^Left::SendInput, ^+{PgUp}
>^Right::SendInput, ^+{PgDn}

Re: close tab with RCtrl

Posted: 03 Jun 2015, 10:13
by usser
thanks, but I don't want to hit RCtrl and arrows

can you tell me a script that would go to next/previous tab with arrows only? and that would work only if the cursor is IBeam (if not possible to make it work only if a blinking vertical line for text exists)

Re: close tab with RCtrl

Posted: 04 Jun 2015, 15:27
by Randy31416
No. Sorry.

Re: close tab with RCtrl

Posted: 04 Jun 2015, 15:46
by usser
why? what is the problem?

Re: close tab with RCtrl

Posted: 04 Jun 2015, 17:28
by Nextron
usser wrote:can you tell me a script that would go to next/previous tab with arrows only? and that would work only if the cursor is IBeam
You mean, not an Ibeam?
Remember that the cursor is the thing that moves with your mouse. The blinky thingy that moves in front of the letters you type is called a caret (and isn't always visible) Because of the obscured way Firefox works, it doesn't tell Windows if it exists or not, so it's difficult to check for. The cursor however is a Windows thing and is easy to check for, but it's only an Ibeam when it hovers over text. So also static selectable text you can't type in, but it's not an Ibeam when you're actually typing but the cursor is hovering someplace else. Regardless of it's usefulness, this is what you'd have to use:

Code: Select all

#If (A_Cursor!="IBeam")
Left::Send ^+{Tab}
Right::Send ^{Tab}
(if not possible to make it work only if a blinking vertical line for text exists)
I can't think of a way that not incredibly difficult and possibly unreliable.

Re: close tab with RCtrl

Posted: 06 Jun 2015, 12:56
by usser
thanks
but how do I combine the two if's?

Code: Select all

#IfWinActive, ahk_class MozillaWindowClass ahk_exe firefox.exe
#If (A_Cursor!="IBeam")
Left::Send ^+{Tab}
Right::Send ^{Tab}
like that?

Re: close tab with RCtrl

Posted: 07 Jun 2015, 04:57
by Nextron
#If (A_Cursor!="IBeam") && WinActive("ahk_class MozillaWindowClass ahk_exe firefox.exe")