62

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 limited by the speed of the keyboard. On both Vista and OS X (I dual boot a MacBook), I have my key repeat rate turned all the way up. But in Visual Studio, and other apps, the rate is still much slower than I would prefer.

How can I make the key repeat rate faster in Visual Studio and other text editors?

nobody
  • 19,814
  • 17
  • 56
  • 77
Frank Krueger
  • 69,552
  • 46
  • 163
  • 208

15 Answers15

87

In Windows you can set this with a system call (SystemParametersInfo(SPI_SETFILTERKEYS,...)).

I wrote a utility for myself: keyrate <delay> <repeat>.

Github repository.

Full source in case that link goes away:

#include <windows.h>
#include <stdlib.h>
#include <stdio.h>

BOOL parseDword(const char* in, DWORD* out)
{
   char* end;
   long result = strtol(in, &end, 10);
   BOOL success = (errno == 0 && end != in);
   if (success)
   {
       *out = result;
   }
   return success;
}


int main(int argc, char* argv[])
{
   FILTERKEYS keys = { sizeof(FILTERKEYS) };

   if (argc == 1)
   {
      puts ("No parameters given: disabling.");
   }
   else if (argc != 3)
   {
      puts ("Usage: keyrate <delay ms> <repeat ms>\nCall with no parameters to disable.");
      return 0;
   }
   else if (parseDword(argv[1], &keys.iDelayMSec) 
         && parseDword(argv[2], &keys.iRepeatMSec))
   {
      printf("Setting keyrate: delay: %d, rate: %d\n", (int) keys.iDelayMSec, (int) keys.iRepeatMSec);
      keys.dwFlags = FKF_FILTERKEYSON|FKF_AVAILABLE;
   }

   if (!SystemParametersInfo (SPI_SETFILTERKEYS, 0, (LPVOID) &keys, 0))
   {
      fprintf (stderr, "System call failed.\nUnable to set keyrate.");
   }

   return 0;
}
Mud
  • 28,277
  • 11
  • 59
  • 92
  • 10
    Wow, this is great. I've been searching for something like this for ages. It works for me on Win 64. Wondering why nobody upvotes this. I'm also wondering how this works internally. It seems like there are the "normal" Settings you can change in the system Settings and you can overwrite them with these. But the "normal" values are still there. Somehow it's layered by design?!? – marc40000 Oct 11 '12 at 14:13
  • Yeah, thanks a lot — now I have the OP's bad habit. (+1) – harpo Dec 30 '13 at 05:47
  • Is this working in windows 8 for anyone? I'm not sure it's having any effect for me. – Alex Vallejo Jan 08 '14 at 14:56
  • Incredible. This instantly sped up a lot of things for me. – blade Feb 07 '14 at 09:23
  • Works great in windows 8. Are you running this from a cmd window and feeding it settings? e.g. keyrate.exe 300 16? – VoidStar Feb 24 '14 at 07:30
  • 1
    This works reasonably well on Windows 7. However, I've had sporadic issues with keys getting stuck until pressed again when using this. This occasionally happens with my ctrl key too, triggering random shortcuts. This is with the delay set to 150ms and the repeat rate to 20ms. – pflaquerre Sep 10 '14 at 20:31
  • /me loves you. After fighting with Windows so much, I finally found your binary. **Awesome** – Benjamin Van Ryseghem Feb 03 '15 at 08:25
  • Thank you! Is it OK if I package the program with something I'm making, and under what terms? – bb94 Oct 16 '15 at 02:07
  • @bb94 No terms. Have at it. – Mud Oct 16 '15 at 02:13
  • 2
    @Mud Thank you this is the best solution in 2018! Tip for others looking to use this: (1) Open Command Prompt (2) Enter `\keyrate.exe ` e.g. `C:\Users\Me\Downloads\keyrate.exe 200 7` (3) Done! – clodal Jan 10 '18 at 07:59
  • This is an awesome little utility; thank you! I added the keyrate.exe call into a little batch file so this would run at startup. (via https://stackoverflow.com/a/54328347/527326) – karan.dodia Dec 04 '19 at 20:46
  • Just verified that it still works in 2021 in Windows 10 Pro 21H1 19043.1151. Really useful to speed up repeat for git bash command line editing! Thank you! You can just download the .exe and run from command line, e.g. /path/keyrate.exe 250 1 – tobi delbruck Aug 08 '21 at 06:50
33

On Mac OS X, open the Global Preferences plist

open ~/Library/Preferences/.GlobalPreferences.plist

Then change the InitialKeyRepeat field. Smaller numbers will speed up your cursor rate. The settings dialog will only set it to a minimum of 2, so if you go to 0 or 1, you'll get a faster cursor.

I had to reboot for this to take effect.

alper
  • 2,919
  • 9
  • 53
  • 102
hyperlogic
  • 7,525
  • 7
  • 39
  • 32
  • 1
    For those of you without BBEdit or TextWrangler (which supposedly can edit binary plist files natively -- I haven't tried it since I don't have those editors), if the global plist file appears to be gibberish, first convert it to xml and then edit it, then convert it back like I had to do. See http://discussions.apple.com/thread.jspa?messageID=8359699 – Eddified Sep 28 '10 at 22:15
  • 1
    You can also install XCode and it will automatically open the Propery List Editor – Ward Bekker Nov 18 '10 at 12:21
  • With Sublime Text, you can do like Eddified said. Just install the Plist Binary then run the De/Encode function. – willdanceforfun Mar 03 '16 at 05:20
  • 1
    Use the built in `defaults` CLI utility to modify preferences like this one. Opening up the file directly will not go well because cfprefsd won't see it automatically. Or use the amazing "Prefs Editor" app. – Chris Mar 09 '23 at 21:09
32

Many times I want to center a function in my window. Scrolling is the only way. Also, Ctrl-left/right can still be slow in code where there are a lot of non-word characters. I use keyboardking also. It has a couple of isssues for me though. One, it sometimes uses the default speed instead of the actual value I set. The other is sometimes it ignores the initial delay. I still find it very useful though. They said 4 years ago they would release the source in 6 months... :(

Ok, on the suggestion of someone that modified HCU\...\Keyboard Response, this works well for me.

[HKEY_CURRENT_USER\Control Panel\Accessibility\Keyboard Response]
"AutoRepeatDelay"="250"
"AutoRepeatRate"="13"
"BounceTime"="0"
"DelayBeforeAcceptance"="0"
"Flags"="59"

Windows standard AutoRepeat delay. 13 ms (77 char/sec) repeat rate. flags turns on FilterKeys? These values are read at login. Remember to log out and back in for this to take effect.

chuckf
  • 429
  • 4
  • 4
  • 2
    Excellent. The only thing I tweaked was setting the DelayBeforeAcceptance down to 0. I found this necessary for using keyboard combinations such as Ctrl+Shift (for setting/unsetting bookmarks). With the delay up at 6, pressing the keys simultaneously, was more often than not "loosing" the second key, resulting in no bookmark being set. – Paul Sep 16 '11 at 11:46
  • 3
    Changing these values does not seem to have any effect on Windows 7 64bit. – marc40000 May 03 '12 at 15:54
  • Paul, thanks. I did change DelayBeforeAcceptance to 0 but I forgot that I had done this. I had to reinstall the other day but my .reg file still had the 6 in it. Had to come back here to remember how to fix the two-key combination not working. Thanks. I'll edit the original for others. – chuckf Jul 10 '12 at 15:42
  • 2
    @marc40000 You have to turn on filter keys, log out and login again for it to work. Confirmed on Win7 64-bit just now. – Will Bickford Mar 30 '16 at 12:52
  • @will-bickford: I just treid this again - and now it works. I can't tell what I did differently those years back. I'm on win 8.1 though now. Thx for posting this comment which made me try this again. :) – marc40000 Apr 03 '16 at 20:14
8

Keyboard preferences window

As mentioned by the hyperlogic, on Mac OS X, internally, there are two parameters dealing with the keyboard speed: KeyRepeat and InitialKeyRepeat. In the System Preferences they are mapped to the Key Repeat Rate and the Delay Until Repeat sliders. The slider ranges and the associated internal parameter values (in parenthesis) are show below. They seem to be multipliers of the 15 ms keyboard sampling interval.

Key Repeat Rate (KeyRepeat)                 Delay Until Repeat (InitialKeyRepeat)
|--------------------------------|          |----------------------|-----------------|
slow (120)                      fast (2)    off (30000)            long (120)        short (25)
0.5 char/s                      33 char/s       

Fortunately, these parameters can be set beyond the predefined limits directly in the ~/Library/Preferences/.GlobalPreferences.plist file. I found the following values most convenient for myself:

KeyRepeat = 1         --> 1/(1*15 ms) = 66.7 char/s
InitialKeyRepeat = 15 --> 15*15 ms = 225 ms

Note that in the latest Mac OS X revisions the sliders are named slightly differently.

exinocactus
  • 83
  • 1
  • 4
8

For Windows, open regedit.exe and navigate to HKEY_CURRENT_USER\Control Panel\Keyboard. Change KeyboardSpeed to your liking.

Jake
  • 2,515
  • 5
  • 26
  • 41
8

Visual Assist has an option to double your effective key movements in Visual Studio which I use all the time.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
8

I'm using KeyboardKing on my PC. It's freeware and it can increase the repeat rate up to 200 which is quite enough. I recommend to set the process priority to High for even smoother moves and less "repeat locks" which happen sometime and are very annoying. With high priority, it works perfectly.

No one understands why we navigate by arrows. It's funny.

3

I don't know how to accelerate beyond the limit, but I know how to skip further in a single press. My knowledge is only in Windows, as I have no Mac to do this in. Ctrl + Arrow skips a word, and depending on the editor it may just skip to the next section of whitespace. You can also use Ctrl + Shift + Arrow to select a word in any direction.

AEM
  • 1,354
  • 8
  • 20
  • 30
Robert K
  • 30,064
  • 12
  • 61
  • 79
3

I do like to work on the keyboard alone. Why? Because when you use the mouse you have to grab it. A time loss.

On the other hand sometimes it seems that every application has its own keyboard type-rates built in. Not to speak from BIOS-properties or OS-settings. So I gathered shortkeys which can be pretty fast (i.e. you are faster typing Ctrl + right(arrow)-right-right than keeping your finger on the right(arrow) key :).

Here are some keyboard shortcuts I find most valuable (it works on Windows; I am not sure about OS X):

ctrl-right: Go to the end of the previous/the next word (stated before)
ctrl-left:  Go to the beginning of the previous/the word before (stated before)
ctrl-up:    Go to the beginning of this paragraph
            (or to the next paragraph over this)
ctrl-down:  Go to the end of this paragraph
            (or to the next paragraph after this)
ctrl-pos1:  Go to the beginning of the file
ctrl-end:   Go to the end of the file

All these may be combined with the shift-key, so that the text is selected while doing so. Now let's go for more weird stuff:

alt-esc:     Get the actual application into the background
ctrl-esc:    This is like pressing the "start-button" in Windows: You can
             navigate with arrow keys or shortcuts to start programs from here
ctrl-l:      While using Firefox this accesses the URL-entry-field to simply
             type URLs (does not work on Stack Overflow :)
ctrl-tab,
ctrl-pageup
ctrl-pagedwn Navigate through tabs (even in your development environment)

So these are the most used shortcuts I need while programming.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Georgi
  • 4,402
  • 4
  • 24
  • 20
  • 2
    Seems like you should investigate vim. – orlp Feb 06 '13 at 19:24
  • @orlp: `]]` `}` `^U` `^D` `53j` `:1207` and of course vim-easymotion... I find it painful to use any other editor now after using Vim "to quickly fix a broken emacs config" a few years ago! – Mark K Cowan Feb 06 '16 at 15:54
3

For OS X, the kernel extension KeyRemap4MacBook will allow you to fine tune all sorts of keyboard parameters, among which the key repeat rate (I set mine to 15 ms, and it works nice).

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
David
  • 31
  • 1
1

Seems that you can't do this easily on Windows 7.

When you press and hold the button, the speed is controlled by Windows registry key : HCU->Control Panel->Keyboard->Keyboard Delay.

By setting this param to 0 you get maximum repeat rate. The drama is that you can't go below 0 if the repeat speed is still slow for you. 0-delay means that repeat delay is 250ms. But, 250ms delay is still SLOW as hell. See this : http://technet.microsoft.com/en-us/library/cc978658.aspx

You still can go to Accesibility, but you should know that those options are to help disabled people to use their keyboard, not give help for fast-typing geeks. They WON'T help. Use Linux, they tell you.

I bieleve the solution for Windows lies in hardware control. Look for special drivers for your keyboards or try to tweak existing ones.

head_thrash
  • 1,623
  • 1
  • 21
  • 26
1

On Mac, it's option-arrow to skip a word and +Shift+Arrow to select. +Arrow skips to the end or beginning of a line or the end or beginning of a document. There are also the page up, page down, home and end keys ;) Holding shift selects with those too.

AEM
  • 1,354
  • 8
  • 20
  • 30
wprl
  • 24,489
  • 11
  • 55
  • 70
1

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 <timo.rumland ${at} gmail.com>, 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!

It's Leto
  • 968
  • 4
  • 17
  • 25
0

Well, it might be obvious, but:

  • For horizontal navigation, Home (line start), End (line end), Ctrl-Left (word left), Ctrl-Right (word right) work in all editors I know

  • For vertical navigation, Page Up, Page Down, Ctrl-Home (text start), Ctrl-End (text end) do too

Also (on a side note), I would like to force my Backspace and Delete keys to non-repeat, so that the only way to delete (or replace) text would be to first mark it, then delete it (or type the replacement text).

AEM
  • 1,354
  • 8
  • 20
  • 30
tzot
  • 92,761
  • 29
  • 141
  • 204
-3

Don't navigate character-by-character.

In Vim (see ViEmu for Visual Studio):

  • bw -- prev/next word
  • () -- prev/next sentence (full stop-delimited text)
  • {} -- prev/next paragraph (blank-line delimited sections of text)
  • /? -- move the cursor to the prev/next occurence the text found (w/ set incsearch)

Moreover, each of the movements takes a number as prefix that lets you specify how many times to repeat the command, e.g.:

  • 20j -- jump 20 lines down
  • 3} -- three paragraphs down
  • 4w -- move 4 words forward
  • 40G -- move to (absolute) line number 40

There are most likely equivalent ways to navigate through text in your editor. If not, you should consider switching to a better one.

Mikael Jansson
  • 4,801
  • 1
  • 24
  • 14
  • 2
    I've been using Vim for 15 years, and I know all the semantic ways of navigating, but I still do tons of navigation via keyboard repeat. It's quite effective *if* you have your key delay dropped very low and your repeat rate very high. It doesn't have to be character-by-character. You can hold down `w`, `j`, ``, etc. to zip around a buffer with pausing to count lines/words/etc. My editor of choice before Vim was the legendary editor [Brief](http://en.wikipedia.org/wiki/Brief_%28text_editor%29) would let you crank the repeat rate to *ridiculous* speeds. – Mud Jun 15 '12 at 17:43
  • @Mud you probably agree that even Visual Assist plugin in Visual Studio doubles keyboard repeat rate with _a reason_. I'm working on my laptop without X installed to avoid procrastination. I've spend a working day googling how to make `kbdrate` using slower delay than 250. Add `atkbd.softrepeat=1` on the kernel command line. – Brian Cannard Aug 04 '17 at 21:09