How can I increase the key repeat rate beyond the OS's limit?

前端 未结 15 1968
攒了一身酷
攒了一身酷 2021-01-29 21:16

I have a bad habit of using the cursor keys of my keyboard to navigate source code. It\'s something I\'ve done for 15 years and this of course means that my navigating speed is

15条回答
  •  Happy的楠姐
    2021-01-29 21:34

    Although the question is several years old, I still come across the same issue from time to time in several different developer sites. So I thought I may contribute an alternative solution, which I use for my everyday-developer-work (since the Windows registry settings never worked for me).

    The following is my small Autorepeat-Script (~ 125 lines), which can be run via AutoHotkey_L (the downside is, it only runs under Windows, at least Vista, 7, 8.1):

    ; ====================================================================
    ; DeveloperTools - Autorepeat Key Script
    ;
    ; This script provides a mechanism to do key-autorepeat way faster
    ; than the Windows OS would allow. There are some registry settings
    ; in Windows to tweak the key-repeat-rate, but according to widely 
    ; spread user feedback, the registry-solution does not work on all 
    ; systems.
    ;
    ; See the "Hotkeys" section below. Currently (Version 1.0), there
    ; are only the arrow keys mapped for faster autorepeat (including 
    ; the control and shift modifiers). Feel free to add your own 
    ; hotkeys.
    ;
    ; You need AutoHotkey (http://www.autohotkey.com) to run this script.
    ; Tested compatibility: AutoHotkey_L, Version v1.1.08.01
    ; 
    ; (AutoHotkey Copyright © 2004 - 2013 Chris Mallet and 
    ; others - not me!)
    ;
    ; @author   Timo Rumland , 2014-01-05
    ; @version  1.0
    ; @updated  2014-01-05
    ; @license  The MIT License (MIT)
    ;           (http://opensource.org/licenses/mit-license.php)
    ; ====================================================================
    
    ; ================
    ; Script Settings
    ; ================
    
    #NoEnv
    #SingleInstance     force
    SendMode            Input 
    SetWorkingDir       %A_ScriptDir%
    
    
    ; Instantiate the DeveloperTools defined below the hotkey definitions
    developerTools      :=  new DeveloperTools()
    
    
    ; ========
    ; Hotkeys
    ; ========
    
        ; -------------------
        ; AutoRepeat Hotkeys
        ; -------------------
    
        ~$UP::
        ~$DOWN::
        ~$LEFT::
        ~$RIGHT::
            DeveloperTools.startAutorepeatKeyTimer( "" )
        return
    
        ~$+UP::
        ~$+DOWN::
        ~$+LEFT::
        ~$+RIGHT::
            DeveloperTools.startAutorepeatKeyTimer( "+" )
        return
    
        ~$^UP::
        ~$^DOWN::
        ~$^LEFT::
        ~$^RIGHT::
            DeveloperTools.startAutorepeatKeyTimer( "^" )
        return
    
        ; -------------------------------------------------------
        ; Jump label used by the hotkeys above. This is how 
        ; AutoHotkey provides "threads" or thread-like behavior.
        ; -------------------------------------------------------
        DeveloperTools_AutoRepeatKey:
            SetTimer , , Off
            DeveloperTools.startAutorepeatKey()
        return
    
    
    ; ========
    ; Classes
    ; ========
    
        class DeveloperTools
        {
            ; Configurable by user
            autoRepeatDelayMs       :=  180
            autoRepeatRateMs        :=  40
    
            ; Used internally by the script
            repeatKey               :=  ""
            repeatSendString        :=  ""
            keyModifierBaseLength   :=  2
    
            ; -------------------------------------------------------------------------------
            ; Starts the autorepeat of the current captured hotkey (A_ThisHotKey). The given
            ; 'keyModifierString' is used for parsing the real key (without hotkey modifiers
            ; like "~" or "$").
            ; -------------------------------------------------------------------------------
            startAutorepeatKeyTimer( keyModifierString )
            {
                keyModifierLength := this.keyModifierBaseLength + StrLen( keyModifierString )
    
                this.repeatKey := SubStr( A_ThisHotkey, keyModifierLength + 1 )
                this.repeatSendString := keyModifierString . "{" . this.repeatKey . "}"
    
                SetTimer DeveloperTools_AutoRepeatKey, % this.autoRepeatDelayMs
            }
    
            ; ---------------------------------------------------------------------
            ; Starts the loop which repeats the key, resulting in a much faster 
            ; autorepeat rate than Windows provides. Internally used by the script
            ; ---------------------------------------------------------------------
            startAutorepeatKey()
            {
                while ( GetKeyState( this.repeatKey, "P" ) )
                {
                    Send % this.repeatSendString
                    Sleep this.autoRepeatRateMs
                }
            }
        }
    
    1. Save the code above in a text file (UTF-8), for example named "AutorepeatScript.ahk"
    2. Install AutoHotkey_L
    3. Double click on "AutorepeatScript.ahk" to enjoy much fast arrow-keys (or put the file into your autostart-folder)

    (You can adjust the repeat delay and rate in the script, see '; Configurable by user').

    Hope this helps!

提交回复
热议问题