Ctrl+tab and shift+ctrl+tab

Get help with using AutoHotkey (v2 or newer) and its commands and hotkeys
becritical
Posts: 21
Joined: 23 May 2016, 03:28

Ctrl+tab and shift+ctrl+tab

22 May 2024, 06:47

Hello All,

I have been trying to painfully transition to V2 but I am stuck on a simple script. I want to set a hotkey so the numpads right and left nagivate around browser tabs. I got the ctrl+tab working but can't get the shift+ctrl+tab to work. Here's what I have.

Any help is appreciated!

Code: Select all

;#HotIf !WinActive("ahk_exe excel.exe")
NumpadRight::^Tab ;Send {LCtrl down}{Tab}{LCtrl up}  ;^Tab 
;NumpadLeft::Send {Shift down}{LCtrl down}{Tab}{LCtrl up}{Shift up}
;#HotIf
[Mod edit: Added [code][/code] tags. Please use them yourself when posting code!]
User avatar
mikeyww
Posts: 27366
Joined: 09 Sep 2014, 18:38

Re: Ctrl+tab and shift+ctrl+tab

22 May 2024, 08:29

Hello,

The documentation may help you. Below is an example of how to use expressions with Send.

https://www.autohotkey.com/docs/v2/lib/Send.htm#ExBrace
becritical
Posts: 21
Joined: 23 May 2016, 03:28

Re: Ctrl+tab and shift+ctrl+tab

23 May 2024, 03:56

mikeyww wrote:
22 May 2024, 08:29
Hello,

The documentation may help you. Below is an example of how to use expressions with Send.

https://www.autohotkey.com/docs/v2/lib/Send.htm#ExBrace
Thank you that works, I was missing the quotes.

It's too bad there's no CtrlTab definition.
Also I don't understand why "^+Tab" does not work in place of sending ctrl and shift down and up. It would be a faster execution probably.
niCode
Posts: 319
Joined: 17 Oct 2022, 22:09

Re: Ctrl+tab and shift+ctrl+tab

23 May 2024, 04:13

NumpadRight::Send('^+{Tab}') works for me. Are you sure you typed it correctly?
RussF
Posts: 1311
Joined: 05 Aug 2021, 06:36

Re: Ctrl+tab and shift+ctrl+tab

23 May 2024, 06:43

@becritical - your original posted code indicated that you are using Excel.

If you are a regular spreadsheet user, one could assume that you regularly use the numpad to enter numbers.

Given that, one could also assume that you have NumLock turned on all the time.

That means that in order to press NumPadLeft or NumPadRight, you ACTUALLY have to hold the Shift key down to do it.

One would also assume that to do that multiple times, you would just hold the Shift key down and press NumPadLeft multiple times in succession.

The problem is that after your script sends the first +^{Tab}, it logically releases the Shift key, even though you are still physically holding it down. Subsequent presses of the NumPadLeft key are actually presses of the NumPad4 key instead, because it thinks Shift is now up.

If you physically release the Shift key between presses of NumPadLeft, it will work as expected.

Russ
RussF
Posts: 1311
Joined: 05 Aug 2021, 06:36

Re: Ctrl+tab and shift+ctrl+tab

23 May 2024, 07:43

I'm sure there are probably more efficient ways to do this, but the following works for me, whether NumLock is on or off and you can continue to hold the Shift key down while pressing the arrow keys if NumLock is on.

Code: Select all

#Requires AutoHotkey v2.0+

NumpadRight::
{
    If GetKeyState("Shift", "P") {
        Send("{Shift Up}^{Tab}{Shift Down}")
    } Else {
        Send("{Shift Up}^{Tab}")
    }
}
NumpadLeft::
{
    If GetKeyState("Shift", "P") {
        Send("+^{Tab}{Shift Down}")
    } Else {
        Send("+^{Tab}")
    }
}

Russ
becritical
Posts: 21
Joined: 23 May 2016, 03:28

Re: Ctrl+tab and shift+ctrl+tab

27 May 2024, 04:39

RussF wrote:
23 May 2024, 06:43
@becritical - your original posted code indicated that you are using Excel.

If you are a regular spreadsheet user, one could assume that you regularly use the numpad to enter numbers.

Given that, one could also assume that you have NumLock turned on all the time.

That means that in order to press NumPadLeft or NumPadRight, you ACTUALLY have to hold the Shift key down to do it.

One would also assume that to do that multiple times, you would just hold the Shift key down and press NumPadLeft multiple times in succession.

The problem is that after your script sends the first +^{Tab}, it logically releases the Shift key, even though you are still physically holding it down. Subsequent presses of the NumPadLeft key are actually presses of the NumPad4 key instead, because it thinks Shift is now up.

If you physically release the Shift key between presses of NumPadLeft, it will work as expected.

Russ
Thank you all for the suggestions. I have removed the code about excel, it was because some issue with a previous version of excel.
In any case now I have these working fine with the numlock off

Code: Select all

NumpadRight::^Tab 
NumpadLeft::Send "{Shift down}{LCtrl down}{Tab}{LCtrl up}{Shift up}"
[Mod edit: Added [code][/code] tags.]

I still don't understand why there isn't a more efficient code for the second action. Which code is more efficient in general?
RussF
Posts: 1311
Joined: 05 Aug 2021, 06:36

Re: Ctrl+tab and shift+ctrl+tab

28 May 2024, 09:09

I don't know what you mean by "more efficient". Do you mean speed of execution or fewer characters to type into the program?

The following works perfectly fine for me with NumLock OFF.

Code: Select all

NumpadRight::^Tab
NumpadLeft::^+Tab

However, the version I posted above works regardless of the state of the NumLock key - of course, if NumLock is on, you will need to hold the Shift key to get to the directional arrows.

So, what is "more efficient" to you? Typing the minimal number of lines to have it work in only one scenario, or typing a few more lines - one time - to have it work in any scenario? Either way, there will be no discernable difference in the speed of execution.

Russ
User avatar
xMaxrayx
Posts: 237
Joined: 06 Dec 2022, 02:56
Contact:

Re: Ctrl+tab and shift+ctrl+tab

28 May 2024, 10:13

yeah it confused with pgdn and pgup.
-----------------------ヾ(•ω•`)o------------------------------
https://github.com/xmaxrayx/
User avatar
xMaxrayx
Posts: 237
Joined: 06 Dec 2022, 02:56
Contact:

Re: Ctrl+tab and shift+ctrl+tab

28 May 2024, 10:36

Ok i figure out you need add line to watch if Ctrl status is up or not, you need to wait until up then send {Ctrl up} but you need to send Tap between them.

maybe you need inputhock object because all hotkeys will pause the other hotkeys threads unlike with input hock only critical call will stop it.


you better leave it now because its way complex, make mistakes with inputhock object is pain.
-----------------------ヾ(•ω•`)o------------------------------
https://github.com/xmaxrayx/

Return to “Ask for Help (v2)”

Who is online

Users browsing this forum: Google [Bot] and 61 guests