我有使用键盘上的光标键浏览源代码的坏习惯。这是我 15 年来一直在做的事情,这当然意味着我的导航速度受到键盘速度的限制。在 Vista 和 OS X 上(我双启动 MacBook),我的按键重复率一直上升。但在 Visual Studio 和其他应用程序中,速度仍然比我希望的要慢得多。
如何在 Visual Studio 和其他文本编辑器中提高键重复率?
我有使用键盘上的光标键浏览源代码的坏习惯。这是我 15 年来一直在做的事情,这当然意味着我的导航速度受到键盘速度的限制。在 Vista 和 OS X 上(我双启动 MacBook),我的按键重复率一直上升。但在 Visual Studio 和其他应用程序中,速度仍然比我希望的要慢得多。
如何在 Visual Studio 和其他文本编辑器中提高键重复率?
在 Windows 中,您可以使用系统调用 ( SystemParametersInfo(SPI_SETFILTERKEYS,...)
) 进行设置。
我为自己写了一个实用程序:keyrate <delay> <repeat>
.
万一链接消失的完整来源:
#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;
}
很多时候我想在我的窗口中居中一个功能。滚动是唯一的方法。此外,在有很多非单词字符的代码中,Ctrl-left/right 仍然会很慢。我也使用键盘。不过,它对我来说有几个问题。一,它有时使用默认速度而不是我设置的实际值。另一个是有时它会忽略初始延迟。我仍然觉得它非常有用。他们在 4 年前说他们将在 6 个月内发布源代码...... :(
好的,根据修改 HCU\...\Keyboard Response 的人的建议,这对我来说效果很好。
[HKEY_CURRENT_USER\Control Panel\Accessibility\Keyboard Response]
"AutoRepeatDelay"="250"
"AutoRepeatRate"="13"
"BounceTime"="0"
"DelayBeforeAcceptance"="0"
"Flags"="59"
Windows 标准自动重复延迟。13 毫秒(77 字符/秒)重复率。标志打开过滤键?这些值在登录时读取。请记住注销并重新登录以使其生效。
在 Mac OS X 上,打开 Global Preferences plist
open ~/Library/Preferences/.GlobalPreferences.plist
然后更改 KeyRepeat 字段。较小的数字将加快您的光标速度。设置对话框只会将其设置为最小值 2,因此如果您选择 0 或 1,您将获得更快的光标。
我必须重新启动才能生效。
对于 Windows,打开 regedit.exe 并导航到HKEY_CURRENT_USER\Control Panel\Keyboard
. 根据您的喜好更改键盘速度。
Visual Assist 有一个选项可以将您在 Visual Studio 中的有效键动作加倍,我一直在使用它。
我在我的电脑上使用键盘王。它是免费软件,它可以将重复率提高到 200,这已经足够了。我建议将进程优先级设置为“高”,以实现更流畅的移动和更少的“重复锁定”,这种情况有时会发生并且非常烦人。具有高优先级,它完美地工作。
没有人理解我们为什么用箭头导航。这很有趣。
正如hyperlogic中提到的,在 Mac OS X 上,内部有两个参数处理键盘速度:KeyRepeat
和InitialKeyRepeat
. 在系统偏好设置中,它们被映射到Key Repeat Rate
和Delay Until Repeat
滑块。滑块范围和相关的内部参数值(括号中)如下所示。它们似乎是 15 毫秒键盘采样间隔的乘数。
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
幸运的是,这些参数可以直接在~/Library/Preferences/.GlobalPreferences.plist
文件中设置超出预定义的限制。我发现以下值对自己最方便:
KeyRepeat = 1 --> 1/(1*15 ms) = 66.7 char/s
InitialKeyRepeat = 15 --> 15*15 ms = 225 ms
请注意,在最新的 Mac OS X 版本中,滑块的名称略有不同。
我不知道如何加速超越极限,但我知道如何一键跳得更远。我的知识仅在 Windows 中,因为我没有 Mac 可以在其中执行此操作。Ctrl+Arrow跳过一个单词,并且根据编辑器的不同,它可能只是跳到空白的下一部分。您还可以使用Ctrl++Shift从Arrow任何方向选择一个单词。
我喜欢一个人在键盘上工作。为什么?因为当你使用鼠标时,你必须抓住它。时间损失。
另一方面,有时似乎每个应用程序都有自己的内置键盘类型速率。更不用说 BIOS 属性或操作系统设置了。因此,我收集了可以非常快的快捷键(即,您键入Ctrl+ 右(箭头)-右-右比将手指放在右(箭头)键上更快:)。
以下是我认为最有价值的一些键盘快捷键(它适用于 Windows;我不确定 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
所有这些都可以与 shift 键结合使用,以便在执行此操作时选择文本。现在让我们来看看更奇怪的东西:
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)
所以这些是我在编程时需要的最常用的快捷方式。
对于 OS X,内核扩展 KeyRemap4MacBook 将允许您微调各种键盘参数,其中包括按键重复率(我将我的设置为 15 毫秒,效果很好)。
在 Mac 上,它是选项箭头来跳过一个单词和⌥</kbd>+Shift+Arrow to select. ⌘</kbd>+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.
似乎你不能在 Windows 7 上轻松做到这一点。
当您按住按钮时,速度由 Windows 注册表项控制:HCU->控制面板->键盘->键盘延迟。
通过将此参数设置为 0,您可以获得最大重复率。戏剧性的是,如果重复速度对你来说仍然很慢,你就不能低于 0。0-delay表示重复延迟为250ms。但是,250 毫秒的延迟仍然非常慢。看到这个:http ://technet.microsoft.com/en-us/library/cc978658.aspx
您仍然可以访问辅助功能,但您应该知道这些选项是为了帮助残疾人使用他们的键盘,而不是为快速打字的极客提供帮助。他们不会帮忙。他们告诉你,使用 Linux。
我相信 Windows 的解决方案在于硬件控制。为您的键盘寻找特殊的驱动程序或尝试调整现有的驱动程序。
尽管这个问题已经有好几年了,但我仍然不时在几个不同的开发者网站上遇到同样的问题。所以我想我可以提供一个替代解决方案,用于我的日常开发人员工作(因为 Windows 注册表设置从未对我有用)。
以下是我的小型 Autorepeat-Script(~ 125 行),可以通过 AutoHotkey_L 运行(缺点是它只能在 Windows 下运行,至少是 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
}
}
}
(您可以在脚本中调整重复延迟和速率,请参阅“;可由用户配置”)。
希望这可以帮助!
好吧,这可能很明显,但是:
对于水平导航,我知道的所有编辑器都可以使用Home(行开始)、End(行结束)、 Ctrl- Left(左字)、Ctrl- (右字)Right
对于垂直导航,Page Up、Page Down、Ctrl- Home(文本开始)、Ctrl- End(文本结束)也可以
另外(附带说明),我想强制我的 Backspace 和 Delete 键不重复,以便删除(或替换)文本的唯一方法是首先标记它,然后删除它(或键入替换文本)。
不要逐个字符地导航。
在 Vim 中(参见ViEmu for Visual Studio):
bw
-- 上一个/下一个词()
-- 上一个/下一个句子(句号分隔的文本){}
-- 上/下一段(文本的空白行分隔部分)/?
-- 将光标移动到找到的文本的上一个/下一个出现处(w/ set incsearch
)此外,每个动作都以数字作为前缀,让您指定重复命令的次数,例如:
20j
-- 向下跳 20 行3}
-- 下三段4w
-- 向前移动 4 个单词40G
-- 移动到(绝对)第 40 行在编辑器中浏览文本很可能有等效的方法。如果没有,你应该考虑换一个更好的。