How to register complex hotkeys - windows

I have a very long list of things I want to trigger with hotkeys in windows. (Unmuting, Playing a soundfile, muting). I have more than 100 soundfiles I want to reach that way, so the normal combinations of windows-hotkeys are not enough (since I do not want to override shortcuts already used by other programs).
My idea is to have something similar to ASCII-codes, where you press ALT-152 to get ÿ for example. Do you know of any tool that allows something like that?
I already tried to use ÿ directly as a hotkey, but that does not seem to work.
Edit: I already tried using autohotkey, but did not manage to achieve my goals (see comment to Santis answer)

I recommend you AutoHotkey, which allows you to program keyboard shortcuts. I always have used it with the classic accelerators (CTRL, ALT, WIN...), but I know it allows two-keys shortcuts.

Related

How to press the Fn + function keys on Windows?

In previous scripts, I have been able to use the SendKeys method to press non-alphabetic keys on my computer like the following to simulate muting,
WshShell.SendKeys(chr(&hAD)).
However, I cannot seem to find the ability to simulate pressing Fn and any of the F1-F12 keys. I am trying specifically to press the "Lower Screen Brightness" key, which is Fn+F11 on my keyboard.
How can this be accomplished?
The Fn keys on a laptop are usually implemented at the hardware or driver level. See: the answer to a similar question: How to press Fn+F11
Your best bet is to find a method of performing the action directly from the OS rather than trying to press a key that doesn't 'exist' as far as Windows is concerned. In the case of screen brightness, there are other ways to do that. This solution is written in C# but if you really needed to do it in VBScript, you could potentially write a COM or DLL to handle it.

Using Alt Key in FakeVim mode of Qt Creator?

It's really handy when you work with VIM text editor to use Alt key to execute normal mode commands in insert mode, for example when you are in insert mode you can press Alt + j to go one line down. But in FakeVim mode of Qt creator this couldn't be done. Any suggestion is welcome.
Pressing Esc each time you want to go to normal mode really sucks.
(not a fix to your problem, just discussing it in a properly formatted text)
I never hit <ESC> as well, and this is a deal breaker for me. Note that it's not a vim feature, though : this behavior occurs because using Alt with an other key in terminals generates an escape sequence. So there's nothing wrong with FakeVim regarding Alt implementation, the problem is related to the IDE being a QT window. You can't use Alt sequence in GTK's Gvim as well, for the same reason, last time I checked.
A possible easy fix on the QCreator part : provide an option to not pass Alt combinations, like the one existing for Ctrl. That is, if QT allows that. We could then at the very least define vim bindings using Alt key to simulate the terminal behavior.
In the list of others exotic combinations from terminals that quickly lead to form habits in vim, I also use C-j in place of <return>, and C-h instead of <backspace>. Those would really be nice to have too :)

How to make xCode "act" as the most normal editors?

I wonder, why doesn't xCode "act" as a normal editor? For example, when I press Ctrl+X, I'd like the current line to be copied-cut. When I press Shift+Tab I'd like the current selection to be shifted to the left, etc. That's the stuff most editors do by default.
How to make it do that?
Take a look at Preferences -> Key Bindings. Here you get a list of actions and their keyboard shortcuts - and you can change those keyboard shortcuts!
It's quite amazing how many actions there are, including a great number of familiar Emacs actions such as mark and yank. Many of them have no corresponding menu item; many of them have no keyboard shortcut by default. Some of them may be the things you are looking for, and all you need to do is change the shortcut if you don't like it. It is very possible that you'll find at least some bindings that you can use to make Xcode behave in a more familiar way.

Remap Caps lock key to Esc in Mma 7

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.

How to hijack the Caps Lock key for Cut, Copy, Paste keyboard operations

Here is what I am trying to accomplish:
To Copy, press and release Caps Lock ONCE
To Paste, press and release Caps Lock TWICE, quickly
To Cut, press Ctrl+Caps Lock
The reason I want to do this is often times i find my self looking down to press the correct X/C/V key, since they're all next to each other (atleast on a QWERTY keyboard).
How can I do this on a standard keyboard (using Windows), so that it applies to the entire system and is transparent to all applications, including to Windows Explorer? If not possible with a standard keyboard, can any of the "programmable numeric keypads" do this you think?
In the above, by "transparent" I mean "the application should never know that this keystroke was translated. It only gets the regular Ctrl+X/C/V code, so it behaves without any problems".
Ps. Not sure of all the tags that are appropriate for this question, so feel free to add more tags.
SOLVED. UPDATE:
Thank you to #Jonno_FTW for introducing me to AutoHotKey.
I managed all three requirements by adding the following AHK script in the default AutoHotKey.ahk file in My Documents folder:
Ctrl & CapsLock::
Send ^x
Return
CapsLock::
If (A_PriorHotKey = A_ThisHotKey and A_TimeSincePriorHotkey < 1000)
Send ^v
Else
Send ^c
Return
That was easy!
NOT COMPLETELY SOLVED. UPDATE:
The above works in Notepad, but NOT in Explorer (copying files for example) or MS Office (even text copying does not work). So, I need to dig around a bit more into AutoHotKey or other solutions. Will post a solution here when I find one.
In the meantime, if someone can make AutoHotKey work for everything I need, please reply!
ALL SOLVED. UPDATE:
All I had to do was to change the capital "C"/X/Z to lowercase "c"/x/z. So Send ^C became Send ^c. It now works in ALL programs inlcuding Windows Explorer! Fixed code above to reflect this change.
I believe the program you are looking for is AutoHotkey.
You need a Global Keyboard Hook.
Very nice! Been looking for something like this for a while.
My script is slightly different, making use of shift or control combinations for cut/copy, then CapsLock on its own is always paste.
Ctrl & CapsLock::
Send ^x
Return
Shift & CapsLock::
Send ^c
Return
CapsLock::
Send ^v
Return
If you wanted to retain the option of retaining the Caps Lock function, I presume you could always remap e.g. Alt-CapsLock for this. I couldn't get it to toggle correctly when I tried it though.

Resources