Jump to content

Detect difference between Ctrl+Tab and Ctrl+Tab+Tab


Recommended Posts

  • Moderators

How can I detect the difference between when I press Ctrl+Tab and Ctrl+Tab+Tab.

I wish to have different events depending on the combination of keys I press.

Can you elaborate a bit more? Is this for an AutoIt GUI? HotKey? ...

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

Wow that was a fast answer !!

Yes, I have a GUI with several Tabs.

If I press Ctrl+Tab, it will change from current to previous Tab.

If I hold down Ctrl and Press Tab numerous of times, it will circle through all Tabs.

Link to comment
Share on other sites

  • Moderators

Wow that was a fast answer !!

Yes, I have a GUI with several Tabs.

If I press Ctrl+Tab, it will change from current to previous Tab.

If I hold down Ctrl and Press Tab numerous of times, it will circle through all Tabs.

That's how I roll ;):D

Have you tried GUISetAccelerators() yet?

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

Short excerpt from my code

Local $l_AccelKeys[2][2] = [["^{TAB}", $l_ChangeTab],["^{TAB}{TAB}", $l_ChangeTab2]]
GUISetAccelerators($l_AccelKeys)

If I put ["^{TAB}", $l_ChangeTab] first it will always use $l_ChangeTab

If I put ["^{TAB}{TAB}", $l_ChangeTab2] first it will always use $l_ChangeTab2

SmOke_N - Do you have any suggestions how I should do to make it work?

Link to comment
Share on other sites

  • Moderators

Short excerpt from my code

Local $l_AccelKeys[2][2] = [["^{TAB}", $l_ChangeTab],["^{TAB}{TAB}", $l_ChangeTab2]]
GUISetAccelerators($l_AccelKeys)

If I put ["^{TAB}", $l_ChangeTab] first it will always use $l_ChangeTab

If I put ["^{TAB}{TAB}", $l_ChangeTab2] first it will always use $l_ChangeTab2

SmOke_N - Do you have any suggestions how I should do to make it work?

Wow... I can't seem to get it to work either.

The only other suggestion is maybe trapping the keys with something like HotKeySet() + a WM_COMMAND registered message.

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

One idea I had was to check if Ctrl was continously pressed, checked what _IsPressed does.

Googled about the DLL that is called, tested what "GetAsyncKeyState" returned, but no success.

Is there a possibility to check if a key has been continously pressed ?

Link to comment
Share on other sites

One idea I had was to check if Ctrl was continously pressed, checked what _IsPressed does.

Googled about the DLL that is called, tested what "GetAsyncKeyState" returned, but no success.

Is there a possibility to check if a key has been continously pressed ?

What about something like this?

#include <GuiConstantsEx.au3>
#include <misc.au3>
#include <GuiTab.au3>

$gui = GUICreate("test")
$Tabs = GUICtrlCreateTab(5, 5, 200)
$Tab1 = GUICtrlCreateTabItem("TAB`1")
$Tab2 = GUICtrlCreateTabItem("TAB`2")
$Tab3 = GUICtrlCreateTabItem("TAB`3")
GUICtrlCreateTabItem("")
$accTabChange = GUICtrlCreateDummy()
Local $l_AccelKeys[1][2] = [["^{TAB}", $accTabChange]]
GUISetAccelerators($l_AccelKeys)
$iTabCount = _GUICtrlTab_GetItemCount($Tabs) - 1

GUISetState()

While 1
    $msg = GUIGetMsg()
    
    Switch $msg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $accTabChange
            While _IsPressed("09"); TAB key is down
                $iCurrentTab = _GUICtrlTab_GetCurSel($Tabs)
                If $iCurrentTab <> $iTabCount Then
                    _GUICtrlTab_SetCurFocus($Tabs, $iCurrentTab + 1)
                Else
                    _GUICtrlTab_SetCurFocus($Tabs, 0)
                EndIf
                Sleep(200);a little pause so the cycling is slowed down
            WEnd
    EndSwitch
WEnd

If you hold down CTRL & TAB it will continuously cycle through the tabs, if you hold down CTRL & press TAB once, it will move to next tab and stop.

Edited by ResNullius
Link to comment
Share on other sites

OK, but if I press Ctrl+Tab once, I want to go back to the last used tab.

Is this closer?

#include <GuiConstantsEx.au3>
#include <misc.au3>
#include <GuiTab.au3>

$gui = GUICreate("test")
$Tabs = GUICtrlCreateTab(5, 5, 200)
$Tab1 = GUICtrlCreateTabItem("TAB`1")
$Tab2 = GUICtrlCreateTabItem("TAB`2")
$Tab3 = GUICtrlCreateTabItem("TAB`3")
GUICtrlCreateTabItem("")
$accTabChange = GUICtrlCreateDummy()

Local $l_AccelKeys[1][2] = [["^{TAB}", $accTabChange]]
GUISetAccelerators($l_AccelKeys)

GUISetState()

$iTabCount = _GUICtrlTab_GetItemCount($Tabs) - 1
$iLastUsedTab = _GUICtrlTab_GetCurSel($Tabs)

While 1
    $msg = GUIGetMsg()
    
    Switch $msg
        Case $GUI_EVENT_CLOSE
            Exit
            
        Case $accTabChange
            $iTabPresses = 0
            $iCurrentTab = _GUICtrlTab_GetCurSel($Tabs)
            While _IsPressed("11"); CTRL key is held down
                If _IsPressed("09") Then; TAB key is pressed
                    While _IsPressed("09"); TAB key is held down
                    WEnd
                    $iTabPresses += 1
                    ConsoleWrite("TAB Presses: " & $iTabPresses & @CRLF & @CRLF)
                EndIf
            WEnd
            
            Switch $iTabPresses
                Case 1
                    _GUICtrlTab_SetCurFocus($Tabs, $iLastUsedTab)
                    
                Case 2
                    $iLastUsedTab = $iCurrentTab
                    If $iCurrentTab <> $iTabCount Then
                        _GUICtrlTab_SetCurFocus($Tabs, $iCurrentTab + 1)
                    Else
                        _GUICtrlTab_SetCurFocus($Tabs, 0)
                    EndIf
            EndSwitch
            
            $iCurrentTab = _GUICtrlTab_GetCurSel($Tabs)
            
    EndSwitch

WEnd
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...