OSX: Programmatically remap Caps Lock's functionality (as set via System Preferences)? - macos

My question is referring to the System Preferences setting that enables you to remap Caps Lock to e.g. Ctrl key.
^ Is it possible to affect this setting programmatically?
Primarily I'd be interested achieving this via defaults or some shell trick; secondarily via AppleScript (yuck).
I know I can probably achieve this by using 3rd party tools, such as KeyRemap4MacBook, but that's a last resort. But I'd rather prefer a non-3rd party solution, if possible.
My use case:
Using Keyboard Maestro and its nice macro triggers, I'm looking to automatically remap Caps Lock -> Ctrl in apps like MacVim, and toggle it back to normal Caps Lock when leaving the affected apps.

You can toggle this using AppleScript. It'll be a simple automation technique, that will basically do the same toggle in System Preferences for you automatically.
You can add the created AppleScript toggle to the MacVim Scripts Toolbar icon. That way, while inside the app you can toggle it, and put it off while leaving.
Is this what you're looking for ? If you still need this I'll design the AppleScript for you and post it in here in a bit.

Related

overriding system-wide (Windows) key shortcuts in Qt app

Ctrl+Escape is a global Windows shortcut for opening main system menu. But I would like my Qt application to use this shortcut without triggering Windows main menu. I know it is probably a bad idea to override system shortcuts in general, but I would like to use this shortcut is a very limited use case.
This usecase is as follows. I have a popup window containing several rows or items. This window is opened by Ctrl+Tab and while the user holds Ctrl and keep pressing Tab, the current rows are cycled through. When the user releases Ctrl, the current row is used for some operation... But sometimes it happens that user presses Ctrl+Tab and then realizes he does not want to continue. He usually presses Escape while still holding Ctrl. And then it triggers Windows system menu and normal user gets confused, choleric user get angry... which is a bad thing. In other words I would like to be able to close the popup window when user presses Ctrl+Escape. How to do that? It is even possible?
If I write the code using this shortcut like any other short, it does not work and it always triggers Windows main menu.
As I understand it, Qt will typically not receive the key event if the underlying window system has intercepted it. For example even QtCreator cannot override system-wide shortcuts.
This question is almost a duplicate of: C++/Qt Global Hotkeys
While that question is asking specifically to capture shortcuts in a hidden/background application, I think the basic concept is the same -- capture shortcuts before the window system processes them.
From that answer, UGlobalHotkey seems pretty good, and the How to use System-Wide Hotkeys in your Qt application blog post could be useful for your limited-use case (but read the comments on that blog post about fixing the example).
Also found:
https://github.com/mitei/qglobalshortcut
https://github.com/Skycoder42/QHotkey (looks like a more detailed version of above)

How do you assign a keyboard shortcut or hotkey in sketchbook pro?

I'm using Sketchbook pro for mac, the documentation that states: "Many of the tools found in the lagoon and menus have assigned hotkeys. You can also check out the Preferences window for a list of them or to remap a tool." However, the link they provide does not give information about how to remap commands.
So trying to switch gears and use hotkeys instead, now the documentation describes a method of assigned hotkeys; however, this doesn't work and nothing happens. Also mysteriously the documentation shows the lagoon with the ability for hotkeys however on my desktop this isn't what I see (see figure below)
Ultimately my goal is to assign commands to my tablet, literally I just want to assign the r key to the rectangle tool instead of the ruler as shown. The problem is that on my Wacom I can only use keystrokes and as it is there is no keystroke for the rectangle command, so frustrating.
It seems like it would be so simple to just "assign keyboard shortcuts in sketchbook pro" but I can't find a single example of it actually happening, I only find references to it being possible, like for example the end of this video see image below:
I don't mind trying to figure out how to use Applescript but I can't find any information on how to talk to sketchbook with applescript. Frustratingly there is an interface to run Applescripts...but no information about how to write applescript to interact with sketchbook commands, see figure:
I'm not sure about applescript, so I hope someone else can help.
You cannot set your own shortcuts inside of SketchBook.
You can only select from the list provided.
In your screen-cap the context of that video is setting your Wacom tablet buttons to Sketchbook hotkeys. That end slide is attempting to communicate that you can use our suggestions (which are listed in the video) or make your own configuration from the available hotkey list. It's not meant to say that you can create your own custom hotkeys.
What are you using the rectangle so much for? 🤔
Regarding AppleScript, I've checked via Autodesk Support and they replied they currently do not support it.
The fact that you see your script appearing in "Sketchbook Pro > Services" is a MacOS feature, it doesn't necessary mean Sketchbook knows about it.

How to map Caps Lock to Esc for Vim in macOS?

I use vim to develop on my mac and I updated to Mountain Lion yesterday. I was using http://pqrs.org/macosx/keyremap4macbook/ this to remap the escape key's function to caps lock to switch between edit and insert modes. I can't really functionally develop in vim without this and it doesn't seem to work in Moutain Lion. I really need a solution soon!
Thanks a lot guys.
Found this:
https://github.com/tekezo/PCKeyboardHack/issues/8#issuecomment-7359829
It worked perfectly for me.
I had grown so accustomed to using caps-lock as esc, that it was killing my productivity until I found this.
You can achieve the same using the accessibility features of macOS. A usage example:
Map Caps Lock to Esc;
Map double Shift to Caps Lock.
To achieve (1) go to Settings > Keyboard > Special keys. In the appeared dialog set the desired mappings.
To achieve (2) go to Settings > Accessibility > Keyboard > Hardware > Activate lock keys.
So now if you have taps on you'll even have a logo on your screen notifying you about that.
NB. These are system-wide settings, not only for vim, but I believe it doesn't make a lot of sense to have a special mapping only for one editor, it will only make things more confusing.
NB. The Settings names could differ slightly for you, since I had to translate them from Dutch. Use some fuzzy logic to get to the right place.

List of globally available shortcuts on a Windows system including 3rd party

Is there a way to get a list of globally available shortcuts on a Windows system, including 3rd party software?
Random examples:
WndHop - WinKey + Enter to move a window between monitors
Dexpot - Ctrl + Spacebar to open task switcher
Launchy - Alt + Spacebar
My goal is to track down shortcut conflicts. Most of the above software can be customised to change the shortcuts aside from WndHop, the later which is not working for me, probably due to a conflict. Currently winkey+enter toggles a windows normal size and maximised, I'm not sure what introduced this shortcut.
I can't see that it would be possible to find all 3rd party short cuts. If an application has created a global keyboard hook to listen for a certain keyboard event there's no way that Windows can tell which keys will make it do various things.
Gathering a universal Shortcut list seems like rather a long winded way to achieve the result you want.
Instead I would suggest a process of elimination.
Start to eliminate apps running on your machine one by one by killing them off using either Task Manager or Process Explorer.
After killing off each of your programs, attempt the key combo in question again and if the action still occurs, then you have not yet found the program in question.
Eventually the effect in question will cease, and you'll know that the last app you killed off was causing this behaviour.

Unable to use X clipboard in Screen

I read the following code in Unix Power Tools on page 117
*VT100.Translations: #override\
Button1 <Btn3Down>: select-end(primary,CUT_BUFFER0,CLIPBOARD)\n\
!Shift <Btn2Up>: insert-selection(CLIPBOARD)\n\
~Shift ~Ctrl ~Meta <Btn2Up>: insert-selection(primary,CUT_BUFFER0)
I have not managed to see any effect of the above code.
How can you use X clipboard in Screen, without your mouse?
Using the mouse. Left-click drag to select and usually the middle mouse button pastes but some terminals may differ (PuTTY uses right-click). If you only have two buttons you click them both together (left mouse button + right mouse button).
In reply to comment below ("Can you do it without your mouse?"):
ctrl-insert : copy
shift-insert : paste
shift-delete : cut
shift-ctrl-C : copy
shift-ctrl-V : paste
Not all applications will support the last three (though Konsole does). In fact most console applications will not allow you to delete text once it's printed.
As far as selecting text without a mouse I'm not sure there's a generic mechanism for that. It's probably terminal and/or application specific (ie, vim has it's own keys for marking and copying text - but only within vim). You could do it with mouse emulation but I'm sure that would be a painful process.
You can't use the traditional Mac/Windows shortcuts in a terminal because they were reserved for different actions long before these OS existed (ie, Ctrl-C terminates the running process).
I'm trying to use Ctrl-C in X
X does not handle these operations directly, they are handled by the application. That's why modern GUI programs like Firefox or Gedit support Ctrl-C for copy but terminals and command-line programs generally do not. As I said, it's a conflict in established conventions and Ctrl-C for kill got in first.
BTW, you could do some key-remapping if it drives you nuts but then you would be learning bad habits when you use a different machine. Best to just get used to it or do most of your editing in a GUI application.
More Information
EDIT: For a Mac, this may help: MacOSX-to-Konsole or This or This. It looks like you need to replace Ctrl with Command on Mac keyboards. It seems like Terminal the mac console has a right-click context menu for copy-paste so to do it the traditional way you me need to install a different console program or change some settings in Terminal.

Resources