Remap keys in OS X - macos

Specifically I'm attempting to map my MacBook's fn key to left mouse click.
Back in the old days when I was using Windows, I came across a wonderful little utility that let me map anything to anything: http://www.autohotkey.com/
You create a little text file, e.g.
^!s:: ; CTRL + ALT + s
Send Sincerely,{enter}John Smith ; sends keystrokes to active window
return
Creating a simple text file was infinitely better than any GUI based remapper.
I can look through it and see everything that is going on at a glance
I can customise every last detail
I can save / retrieve / post / share my scripts
Really, it's the one thing I really miss about Windows.
So my question is: How do I go about doing this in OS X? Every Google search leads to https://pqrs.org/macosx/keyremap4macbook/ and I dislike this package: it has an insanely cluttered GUI.
I would be very happy if I could do it in a shell script, or even compile code.

HotKeys on OS X
Even though AHK is seemingly absent on Mac, the functionality that AHK provides on Windows can likely be achieved in OS X. It could be a matter of coding your own solution, modifying something that's open-source, or using a combination of applications that will work together. I haven't tried all of the following, but might as well mention them as they might be worth checking out:
Open Source
IronAHK - .NET rewrite of AHK ported to OS X
AHK Forum Thread
Github Project
*the original project might be dead
CliClick - command-line application that will emulate mouse clicks
Github Project
Commercial
TextExpander - scriptable text completion / hotkey / macro app (supports AppleScript, Shell scripts)
Typinator - similar to TextExpander, although some features vary.
KeyMo - mostly for mapping keys exclusively to your mouse.
FastScripts - maps hotkeys/user-definable keyboard shortcuts to AppleScripts
*I use Text Expander and FastScripts together and can't live without them.
Rolling Your Own
It's fairly easy to create something with an AppleScript, or a shell script for just about anything imaginable in OS X. For example, I've seen CliClick used along with a custom AppleScript to achieve a certain functionality that it might not provide otherwise. To find an AHK replacement on Mac it'll probably be through trial and error, patience, and ultimately what ends up working best for you.

It is possible with a program called ControllerMate, instructions here. It is, however, a commercial software. I'm also interested in finding a free alternative.

Sikuli project looks promising. Not sure about your particular problem (e.g. Fn key remapping), but it's definitely a crossplatform alternative to AHK.

Another Open Source solution to this problem not mentioned in l'L'l's answer is Karabiner; I have been looking for a way to remap the key to the left of 1 to Esc for a while, and this worked perfectly. It even resolved an issue I was having where swapping Cmd and Alt using the built in OSX key remapping was breaking terminal Alt shortcuts! Highly recommend it.

Related

Identifying menu system

Back when I was a kid, we used an old MS-dos system to navigate programs, menus and games. All I can seem to remember is that we started the program by typing "menu" (or it was in the autoexec). I can't recall further about the name.
This was back in the beginning of the 90'es, but the system could have been developed earlier, but I recall using the cd and cd.. to navigate earlier than that.
I also remember that you could edit the menus by adding/removing items by pressing SHIFT-F[x] (I could be wrong about the shift, but it was an modifier and an F-key), and an item was added by modifying a number of batch-commands. This could either be a new page of menues or a command to a program.
My memory tells me that it looks something like this;
Can anyone tell me more about what this program was called and maybe even if it is available as download somewhere?
(Edit: Updated title)
I remember DrMenu and Fixed Disk Organizer (from IBM) but I don't remember their appearance.
I remember a similar program on my fathers PC (or rather AT) back in the late 80's/early 90's. I think it was made by Scandinavian PC Systems, or SPCS for short. I doubt Visma (that now own the brand SPCS) have it for download somewhere, and my answer is not a complete answer but I can not add a comment so I hope you excuse me for trying to help out in this way.

AutoHotkey - persistent keystroke expansion? - HotStrings

I am having trouble understanding how this product works. In the old days of Windows 3.1 and 95 I used these things called "hotkeys" where, no matter where I was in Windows, I could hit a certain key combination and it would happen. I assumed that was what this program did. Is it really just a scripting language?
I followed the "quick start" tutorial in the help file and it talks about creating a script and how to set strings for keystroke patterns to expand into. However, I created this simple script and put it in an AHK file on my Desktop:
::gsell::
Great Seller! A++++++++++++++++++++++++++++++++
Return
When I run the script from my desktop it appears to complete pretty much instantly, and of course it does nothing because I am on my desktop. I assumed there was some way to actually use these hotkeys in other applications, but it is not obvious to me and I've made a fair effort. Is this just an automation scripting language, or is there some simple way to set up some simple hotkeys and have them persist across applications?
Hotkeys and Hotstrings are available globally by default. Your issue with the expansion is likely because you have special characters that need to be escaped. Try the following:
::gsell::Great Seller{!} A{+}
; Simple Hotkey - Ctrl+F1
^F1::Msgbox, You pressed a hotkey
I decided to try an example from the help file and it did work. Apparently the place where I thought it was telling me the script was closed, was actually saying the script was still running, and it counts the number of seconds when you refresh. For some reason the text expansion is still not working, but this question is pretty much solved.

is it possible to map Vim key bindings for windows, just like vimium for chrome

is it possible to map Vim key bindings for windows? just like vimium for chrome. I don't like the mouse sometimes.
using vimium, I can press 'f' to generate 'names' for the link, and just press the name to open the link, it's awesome!
This is an AutoHotKey script that implements some of the vim functions in all applications.
Also LabelControl provides some label support, like vimium, but it's not always that useful.
you can use hunt-n-peck .
you should download binaries from continous integration artifacts.
this is the hunt-n-peck binaries zip link HuntAndPeck taken from repository's continuous integration artifacts.
I don't know about any existing tool, but macro tools like AutoHotkey allow to implement that. For a purely modal solution like in Vim, you'd need to save the mode state (and probably also indicate it somehow), which is difficult. Creating vim like functionality with autohotkey ahk outlines a solution (for navigation) that relies on another simultaneously pressed key instead.
To answer the stated question: Yes, and there exists several, but they have limitations. The best way that I know of is using AutoHotkey, which can be used to add several of Vim's features.
Due to how Vim commands work, it is only partially possible, as implemented in several forms. For several examples you can search for e.g. "autohotkey vim".

Which programming language is most fit for implementing a windows form dialog?

And how?
I want to implement an simple enough dialog with several buttons.
vb.net or c#.net both use .net framework. You can create a windows forms project that has rich user interface for buttons,forms,labels,grids... it is also very simple to start with using visual studio beucase visual studio has options to write parts of the code for you.
One of the easiest ways to get some simple dialogs and a bit of associated code running in Windows is AutoHotKey. It's free-as-in-beer, too.
It's a macro script environment where you can write little programs as scripts (and hook them to keys, that's where it got its name and original purpose).
AHK is a BASIC-like tiny scripting language that's all about simplicity and ease of use. Good enough for most small projects you'd care to do.
One use case/experience
I'm not a Windows programmer at all; I used to program in Delphi a bit, but now I'm mostly working in Java. Recently my girlfriend needed a bit of hacking: She bought a product with a registration key, and part of that key was smudged off the sticker. What we needed was a program to brute-force try all the possible missing letters/numbers in the program's registration dialog. Legitimate hacking, if you will.
I considered doing this in Delphi, then I started thinking about which arcane system calls I'd be needing to reach into the GUI of another program and to poke text into the input dialog... it turned out to be very easy in AHK. I needed about 10 minutes to write my hacking program, and it took about 5 minutes to find the right key.
If I remember correctly, my little program even included a dialog for specifying what we knew of the key, and which places had to be trial-and-errored. And of course a "start" button.
Update with example
I really wish I still had that little script I wrote as described above, but it's been several years and I've thrown it away.
I dug up this little gem on the net:
This is a working example script that uses a timer to change the names of the buttons in a MsgBox dialog. Although the button names are changed, the IfMsgBox command still requires that the buttons be referred to by their original names.
#SingleInstance
SetTimer, ChangeButtonNames, 50
MsgBox, 4, Add or Delete, Choose a button:
IfMsgBox, YES
MsgBox, You chose Add.
else
MsgBox, You chose Delete.
return
ChangeButtonNames:
IfWinNotExist, Add or Delete
return ; Keep waiting.
SetTimer, ChangeButtonNames, off
WinActivate
ControlSetText, Button1, &Add
ControlSetText, Button2, &Delete
return
I agree that this is a silly and useless program; I found it quite hard to find useful small examples on the 'net. Most of the people who write AHK scripts seem to enjoy hanging bells and whistles off their creations until they end up being full-fledged applications and no longer suitable as small examples.
A lot of useful snippets of code, though, can be found in AHK's Tutorial and overview:
http://www.autohotkey.com/docs/Tutorial.htm
Much of what they talk about is hanging certain capabilities off certain keys. This is how AHK started, but meanwhile it's a (mostly) full-fledged Windows programming language. So don't pay too much attention to the key mapping stuff.
Here's a cute little script to run Notepad and then issue a message box:
RunWait Notepad
MsgBox The user has finished (Notepad has been closed).
Here's a small dialog to get some input from a user:
MsgBox, 4, , Would you like to continue?
IfMsgBox, No
return
; Otherwise, the user picked yes.
MsgBox You pressed YES.

Safe keyboard shortcut for activating code completion style functionality in Mac OS X browsers

I'm building some code completion style text expansion functionality for text areas and inputs in a web application. I'm trying to work out a safe keyboard shortcut for invoking the completion proposals for browsers running on Mac OS X.
I've eliminated some potential candidates:
Command + Space - activates the Spotlight search field
Control + Space - activates the context menu in Firefox
Esc - cancels any background XMLHttpRequests in Firefox
That leaves Option + Space. I'm aware that may conflict with tools like Ubiquity, but that's something we don't expect our audience to be using.
Are there any conflicts I may have missed with Option+Space? Or do you have a better idea for a keyboard shortcut, and why?
A lot of Mac OS X apps use Option + Esc to do code completion or code hints.
Some kind of tab shortcut sounds like the best and most intuitive approach - users should be used to the 'type-tab-type-tab' workflow - maybe combine it with a modifier if it only wants to be optional.
As I recall, Visual Studio and TextMate both use tab to code-complete. In Visual Studio an intellisense menu pops up as you start typing and tab acts as the selection confirmation.
In TextMate, you start typing part of a command then hit tab to activate said command's associated "bundle". The associated bundle typically generates a code snippet and fills in any dynamic parts of the snippet as you type.
Come to think of it, most command lines work this way as well, auto-completing file names and paths when tab is pressed after typing a few characters.
EDIT: You say tabs are needed for field switching in a web interface, but you may want to try intercepting the keyboard event in the textfield, and check if they're started typing a macro. If they have, auto-complete and swallow the key by returning false; if not, simply let the command bubble through.
I discussed these ideas with our design team. One of them suggested using Control + Enter, which is what we decided to go with. This causes forms that only contain a single input field to automatically submit in Firefox, but we deal with that by preventing the default action caused by the event.
I re-assigned the Spotlight command to Command + Shift + Space. This is easily done via Prefrences.App

Resources