Jump to content

Remap Win+Tab to Ctrl+Tab


Recommended Posts

Hi, folks!

Is it possible to remap Win+Tab to Ctrl+Tab? I have tried this way:

HotKeySet("#{Tab}", "WinTab")
ProcessWait("")

Func WinTab()
     Send("^{Tab}")
EndFunc

But this didn't work, because Windows has the #{Tab} shortcut to shift between programs in taskbar.

Did I miss something? I could workaround the problem using AutoHotKey instruction "#Tab::^Tab", but I just love AutoIt, and I would feel like a betrayer flirting with another scripting language, so I want to avoid this at any cost. Can you help to keep me loyal? :P

Thanks in advance!

Reginald0

Link to comment
Share on other sites

Hi,

You can not set Win hotkey with HotKeySet because it's preserved by windows.

But i think you can make it with Keyboard hook, something like this:

HotKeySet("{ESC}", "OnAutoItExit")

Opt("SendKeyDownDelay", 0)
Opt("SendKeyDelay", 0)

Global Const $WH_KEYBOARD_LL = 13

Global $sBuffer = ""
Global $hStub_KeyProc = DllCallbackRegister("_KeyProc", "int", "int;ptr;ptr")
Global $hMod = DllCall("kernel32.dll", "hwnd", "GetModuleHandle", "ptr", 0)
Global $hHook = DllCall("user32.dll", "hwnd", "SetWindowsHookEx", "int", _
    $WH_KEYBOARD_LL, "ptr", DllCallbackGetPtr($hStub_KeyProc), "hwnd", $hMod[0], "dword", 0)

While 1
    Sleep(10)
WEnd

Func _KeyProc($nCode, $wParam, $lParam)
    Local $aRet, $KEYHOOKSTRUCT
    
    If $nCode < 0 Then
        $aRet = DllCall("user32.dll", "long", "CallNextHookEx", "hwnd", $hHook[0], "int", $nCode, "ptr", $wParam, "ptr", $lParam)
        Return $aRet[0]
    EndIf
    
    If $wParam = 256 Then
        $KEYHOOKSTRUCT = DllStructCreate("dword;dword;dword;dword;ptr", $lParam)
        
        Local $nKeyCode = DllStructGetData($KEYHOOKSTRUCT, 1)
        
        If $sBuffer = 91 And $nKeyCode = 9 Then
            $sBuffer = ""
            
            Send("^{Tab}")
            
            Return 1
        EndIf
        
        $sBuffer = $nKeyCode
    EndIf
    
    $aRet = DllCall("user32.dll", "long", "CallNextHookEx", "hwnd", $hHook[0], "int", $nCode, "ptr", $wParam, "ptr", $lParam)
    
    Return $aRet[0]
EndFunc   ;==>_KeyProc

Func OnAutoItExit()
    If $hStub_KeyProc Then DllCallbackFree($hStub_KeyProc)
    $hStub_KeyProc = 0
    
    DllCall("user32.dll", "int", "UnhookWindowsHookEx", "hwnd", $hHook[0])
    If @HotKeyPressed <> "" Then Exit
EndFunc   ;==>OnAutoItExit

 

Spoiler

Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1

AutoIt_Rus_Community.png AutoIt Russian Community

My Work...

Spoiler

AutoIt_Icon_small.pngProjects: ATT - Application Translate Tool {new}| BlockIt - Block files & folders {new}| SIP - Selected Image Preview {new}| SISCABMAN - SciTE Abbreviations Manager {new}| AutoIt Path Switcher | AutoIt Menu for Opera! | YouTube Download Center! | Desktop Icons Restorator | Math Tasks | KeyBoard & Mouse Cleaner | CaptureIt - Capture Images Utility | CheckFileSize Program

AutoIt_Icon_small.pngUDFs: OnAutoItErrorRegister - Handle AutoIt critical errors {new}| AutoIt Syntax Highlight {new}| Opera Library! | Winamp Library | GetFolderToMenu | Custom_InputBox()! | _FileRun UDF | _CheckInput() UDF | _GUIInputSetOnlyNumbers() UDF | _FileGetValidName() UDF | _GUICtrlCreateRadioCBox UDF | _GuiCreateGrid() | _PathSplitByRegExp() | _GUICtrlListView_MoveItems - UDF | GUICtrlSetOnHover_UDF! | _ControlTab UDF! | _MouseSetOnEvent() UDF! | _ProcessListEx - UDF | GUICtrl_SetResizing - UDF! | Mod. for _IniString UDFs | _StringStripChars UDF | _ColorIsDarkShade UDF | _ColorConvertValue UDF | _GUICtrlTab_CoverBackground | CUI_App_UDF | _IncludeScripts UDF | _AutoIt3ExecuteCode | _DragList UDF | Mod. for _ListView_Progress | _ListView_SysLink | _GenerateRandomNumbers | _BlockInputEx | _IsPressedEx | OnAutoItExit Handler | _GUICtrlCreateTFLabel UDF | WinControlSetEvent UDF | Mod. for _DirGetSizeEx UDF
 
AutoIt_Icon_small.pngExamples: 
ScreenSaver Demo - Matrix included | Gui Drag Without pause the script | _WinAttach()! | Turn Off/On Monitor | ComboBox Handler Example | Mod. for "Thinking Box" | Cool "About" Box | TasksBar Imitation Demo

Like the Projects/UDFs/Examples? Please rate the topic (up-right corner of the post header: Rating AutoIt_Rating.gif)

* === My topics === *

==================================================
My_Userbar.gif
==================================================

 

 

 

AutoIt is simple, subtle, elegant. © AutoIt Team

Link to comment
Share on other sites

MrCreatoR, thanks for your response, and it really works, but I think you'll agree with me that there's a lot of code complexity for such a simple task: remap a key.

And if Winkey is preserved by Windows, why another script language can handle it? In my point of view, a keyboard hook is done outside the AutoIt intelligence, so I don't understand why AutoIt developers don't treat this kind of situation inside the HotKeySet instruction, cause the remapping of F12 key bring us the same problem.

But anyway, thanks again for you attention.

Reginald0

Link to comment
Share on other sites

The windows key or start key is not preserved by windows. Only a number of buttons are reserved by Windows because they do a variety of tasks that are always should be enabled (Alt+Tab, Start+E, Start+F, etc. etc.) If you really want to remap a Windows Hotkey, then that should be done using the registry to remap the keys.

AutoIt's HotKeySet uses the RegisterHotkey function. Look at it on MSDN. Because it uses that RegisterHotkey it also is bound between the limits of that function.

The RegisterHotkey can also be called in AutoIt directly, and you'll see the limitations more easily. Look here for an example: http://www.autoitscript.com/forum/index.ph...t=0#entry515994

Link to comment
Share on other sites

Manadar, thanks for your response too, but I can't agree when you say that if I really want to remap a Windows hotkey, that should be done using the registry, just because another script language (already cited on first post) much similar to AutoIt can do that job without much hassle with just one little instruction. Ok, I know it's a different application, but AutoIt is so much better, so is out of my comprehension why this is not implemented inside the HotKeySet instruction.

Link to comment
Share on other sites

  • 3 years later...

Hi folks!

Sorry for bumping this old thread, but till this day, I'm using the somewhat "ugly" ;) AutoHotkey solution, and to make things worse, MrCreatoR solution is not working properly in Windows 7, since sometimes it sends just the "Win" key, sometimes "Ctrl+Tab", and sometimes "Win+Tab".

I really hope with the time has passed since the first post (almost 4 years), AutoIt has a nice solution for this seemingly simple issue.

Thanks in advance.

Reginald0

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...