将大写锁定键重新映射到Mma 7中的Esc [英] Remap Caps lock key to Esc in Mma 7

查看:111
本文介绍了将大写锁定键重新映射到Mma 7中的Esc的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

TLDR :如何使CapsLock转换为Mma 7中的"ShortNameDelimiter"?

我喜欢mma笔记本中的漂亮文字,并且经常将函数定义为f[\[Alpha]_] =...,以便与我正在使用的精确方程式匹配.因此,它涉及许多 Esc -字母- Esc 序列,并且每隔一个笔画就达到 Esc 破坏了我的打字流程.

现在,很少使用 CapsLock 键(我不记得上一次需要它了),但放置方便(您的小指就在那儿!).将其重新映射到vim上的 Esc 对我来说是一个奇迹,我想知道是否可以在mma中进行相同的操作而不必修改系统的键盘布局.

我尝试通过在EventTranslations[{...

中添加以下内容来编辑KeyEventTranslations.tr

Item[KeyEvent["CapsLock"], "ShortNameDelimiter"]

但是没有效果.还有另一种方法吗? CapsLock不是正确的标识符吗?如果有帮助,我正在Mac上使用Mma7学生版.

解决方案

修饰符键的处理方式很特殊,我怀疑Mathematica是否能够覆盖系统.您可能必须在Mathematica和操作系统之间的某一层中执行此操作.但是,可以根据所使用的应用程序使键的行为有所不同.因此,通过一些工作,可以使 capslock键的行为仅在Mathematica中有所不同.

我没有看到您说您使用的是哪个操作系统,所以我添加了Mac说明.


Windows

例如,如果您使用Windows,则可以使用名为 http://www.autohotkey.com/<的程序/a>.它特别具有一项功能,您可以将密钥绑定到脚本,特别是以下脚本:

如何使热键或热字符串仅对某些程序专有?

换句话说,除了特定的窗口处于活动状态之外,我希望某个键能够像往常一样起作用. 在下面的示例中,使NumpadEnter正常执行,除非出现标题为"CAD Editor"的窗口.活跃.注意在"$ NumpadEnter"中使用$前缀,这是使热键发送自己"所需的:

$NumpadEnter::
IfWinNotActive, CAD Editor
{
    Send, {NumpadEnter}
    return
}
; Otherwise, the desired application is active, so do a custom action:
Send, abc
return

该下一个示例比上面的示例更加纯正,但是只有在"CAD编辑器"应用程序旨在忽略NumpadEnter键本身.代字号前缀(〜)使NumpadEnter成为不受抑制的热键,这意味着NumpadEnter击键本身总是发送到活动窗口,唯一的不同是它触发了热键操作. 〜功能需要Windows NT/2k/XP.

~NumpadEnter::
IfWinNotActive, CAD Editor
    return
; Otherwise, the desired application is active, so do a custom action:
Send, abc
return

引用"MRCS"在此论坛帖子中,您可能会发现以下有用的信息:

第一个我命名为CapsLockR.ahk并包含以下脚本:

CapsLock UP::Run C:\Documents and Sett...[path to script]...\CapsLock.ahk 

第二个名为CapsLock.ahk并具有以下脚本:

GetKeyState, state, CapsLock, T 
if state = D 
    SetCapsLockState, off 
else 
    SetCapsLockState, on 
exit

因此,如果您在修改如果活动窗口= Mathematica时行为类似Foo,否则表现得像Bar"那样麻烦,则情况变得更糟.脚本,您可以对此进行设置以手动切换我认为的CapsLock状态.谷歌搜索还将显示更多结果.


Linux

我知道在Linux上,您可以使用名为xbindkeys的程序将CapsLock绑定到脚本,如果您检测到Mathematica是最顶层的窗口之一(例如,通过获取最顶部窗口的pid和详细信息xdotool getwindowfocus),或更糟糕的是最糟糕的是,您只能使用一个脚本来在CapsLock -> xdotool key Escape, xdotool type "whatever", xdotool key Escape("Mathematica模式")和正常模式"之间切换配置,尽管这可能会阻止您在即时消息传递时对数学家大喊大叫做数学.除非您可能需要找到某种以编程方式切换CapsLock的方法,否则也许可以通过创建一个虚拟CapsLock密钥(尽管这是一个极端的技巧,很可能可以找到某种类型的库;也许 http://pqrs.org/macosx/keyremap4macbook/extra.html 将CapLock键重新映射到某种东西,这将告诉OS X让您重新映射CapsLock.然后重新映射它,然后使用Quicksilver将密钥绑定到一个脚本,该脚本进行调用xdotool来检查您是否在Mathematica中,并且还会发出:esc:...:esc:(请参见此答案的Linux部分).否则,您将模拟CapsLock上的按键.但是您重新映射了CapsLock!因此,您可能需要在CapsLock密钥中使用另一个从未使用过的虚拟密钥,并使用Cocoa库或简单的AppleScript触发对该虚拟密钥的按键操作.如果您想使用CapsLock路线,可能会发现将Caps Lock用作Mac OS X中的Esc 有用.

TLDR: How do I get CapsLock to translate to "ShortNameDelimiter" in Mma 7?

I like pretty text in my mma notebooks, and often define functions as f[\[Alpha]_] =... so as to match the exact equation that I'm working with. As such, it involves a lot of Esc-letter-Esc sequences, and reaching for Esc every other stroke breaks my flow of typing.

Now, the CapsLock key is seldom used (I can't remember the last time I needed it), but conveniently placed (your pinky is right there!). Remapping it to Esc on vim worked wonders for me and I was wondering if there was a way to do the same in mma, without having to modify the system's keyboard layout.

I tried editing KeyEventTranslations.tr by adding the following in EventTranslations[{...

Item[KeyEvent["CapsLock"], "ShortNameDelimiter"]

but that had no effect. Is there another way to do it? Is CapsLock not the correct identifier? If it helps, I'm using Mma7 student version on a Mac.

解决方案

Modifier keys are handled quite specially, and I doubt Mathematica will be able to override the system. You probably have to do this in a layer between Mathematica and the OS. BUT, it is possible to make the key behave different depending on the application you are in. Thus with a bit of work, it MAY be possible to have the capslock key behave differently only in Mathematica.

edit: I did not see you say which operating system you had, so I've added Mac instructions.


Windows

For example, if you have Windows, you can use the program called http://www.autohotkey.com/ . It specifically has a feature where you can bind a key to a script, specifically the following script:

How can a hotkey or hotstring be made exclusive to certain program(s)?

In other words, I want a certain key to act as it normally does except when a specific window is active. In the following example, NumpadEnter is made to perform normally except when a window titled "CAD Editor" is active. Note the use of the $ prefix in "$NumpadEnter", which is required to let the hotkey "send itself":

$NumpadEnter::
IfWinNotActive, CAD Editor
{
    Send, {NumpadEnter}
    return
}
; Otherwise, the desired application is active, so do a custom action:
Send, abc
return

This next example is more pure than the above, but it will only work if the "CAD Editor" application is designed to ignore the NumpadEnter key itself. The tilde prefix (~) makes NumpadEnter into a non-suppressed hotkey, meaning that the NumpadEnter keystroke itself is always sent to the active window, the only difference being that it triggers a hotkey action. The ~ feature requires Windows NT/2k/XP.

~NumpadEnter::
IfWinNotActive, CAD Editor
    return
; Otherwise, the desired application is active, so do a custom action:
Send, abc
return

To quote from "MRCS" in this forum post, you may find the following useful:

The first one I named CapsLockR.ahk and contains the following script:

CapsLock UP::Run C:\Documents and Sett...[path to script]...\CapsLock.ahk 

The second one is named CapsLock.ahk and has this script:

GetKeyState, state, CapsLock, T 
if state = D 
    SetCapsLockState, off 
else 
    SetCapsLockState, on 
exit

Thus worse comes to worst, if you are having trouble modifying the "Behave like Foo if Active Window = Mathematica else behave like Bar" script, you can tack on this to manually toggle the CapsLock state I think. Googling will also reveal more results.


Linux

I know that on Linux, you can use the program called xbindkeys to bind the CapsLock to a script, from which you can in turn call xdo if you detect Mathematica is one of the topmost windows (e.g. via Getting pid and details for topmost window , or xdotool getwindowfocus) or worse-comes-to-worst, you can just have a script which toggles your configuration between CapsLock -> xdotool key Escape, xdotool type "whatever", xdotool key Escape ("Mathematica mode") and "normal mode"... though that may prevent you from YELLING AT MATHEMATICIANS OVER INSTANT MESSAGING WHILE DOING MATHEMATICS. Unless you You may need to find some way to programatically toggle CapsLock, perhaps by creating a dummy CapsLock key (though that's an extreme hack, it is likely one can find some kind of library; perhaps Anybody know how to toggle caps lock on/off in Python? may be useful). (This issue could be avoided by using a key besides CapsLock, or not caring that you want to keep your CapsLock functionality; you could also just turn another key you never use into CapsLock.)


Mac

Mac may have similar tools. For example, you can get xdotool like on Linux above via the MacPorts project. I hear the CapLock key cannot normally be rebound as easily on Mac, so if you can deal with another key it may be much easier. But theoretically it should be possible...

If you wish to use CapsLock, you can use PCKeyboardHack http://pqrs.org/macosx/keyremap4macbook/extra.html to remap the CapLock key to something which will tell OS X to let you remap the CapsLock. Then you remap it, then bind the key using Quicksilver to a script that makes calls xdotool to check if you're in Mathematica also also to issue the :esc:...:esc: if you are (see the Linux section of this answer). Otherwise you simulate a keypress on the CapsLock. But you remapped CapsLock! So you might need to make another dummy key you never use into the CapsLock key, and trigger a keypress on that using Cocoa libraries or a simple AppleScript. If you wish to pursue the CapsLock route, you might find Using Caps Lock as Esc in Mac OS X useful.

这篇关于将大写锁定键重新映射到Mma 7中的Esc的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆