Key-remapping using Macbook command-line - macos

The "delete" key on my Macbook is broken. I am attempting to use the hidutil command to remap F1 as my new delete key. The command isn't performing as expected.
The command requires the hex ID's for the keys whose values I'd like to interchange. I've located a resource that provides these hex ID's as well as an overview of how to perform the remapping (https://developer.apple.com/library/archive/technotes/tn2450/_index.html).
I've posted my specific code below. It adheres to the suggested format, but my OS doesn't seem to register any change. Can someone help me identify the issue? I suspect my Hex ID's are wrong, but it may very well be another issue.
Input :
hidutil property --set '{"UserKeyMapping":[{"HIDKeyboardModifierMappingSrc":0x2a,"HIDKeyboardModifierMappingDst":0x3a}, {"HIDKeyboardModifierMappingSrc":0x3a,"HIDKeyboardModifierMappingDst":0x2a}]}'
Output :
UserKeyMapping:(
{
HIDKeyboardModifierMappingDst = 58;
HIDKeyboardModifierMappingSrc = 42;
},
{
HIDKeyboardModifierMappingDst = 42;
HIDKeyboardModifierMappingSrc = 58;
})
There are no error objects. And judging by the output after the command is run some key remapping has occurred. However, my F1 key still retains functionality as F1 and doesn't delete I'd expected.

Your referenced link on apple.com says "The keys take a hexadecimal value that consists of 0x700000000 or’d with the desired keyboard usage value." So I think you should try e. g. HIDKeyboardModifierMappingSrc":0x70000002a ...

Thanks for the above information, I was able to remap the right Ctrl key to be the Command key on the mac with the following command.
% hidutil property --set '{"UserKeyMapping":[{"HIDKeyboardModifierMappingSrc":0x7000000e4,"HIDKeyboardModifierMappingDst":0x7000000e3}]}'
This is because I am using a very old IBM original keyboard that does not have a windows key, just an empty space between the Ctrl and Alt keys on the left and right of the Space bar.

Related

How to cancel the binding of option key in OSX?

I know that OXS bind special keys on option key, such as option+y=¥,option+t=þ... But now, I want to cancel all these bindings, and use option+character as the shortcuts in JetBrains IDEs and other apps.
I have searched for hours and still haven't found a useful way.Can anyone share a tool or the correct way?I used the way to add Library/KeyBindings/DefaultKeyBinding.dict file, but it only canceled some key-bindings, not work for all.
It is my DefaultKeyBinding.dict file below :
{
"~d" = "deleteWordForward:";
"^w" = "deleteWordBackward:";
"~f" = "moveWordForward:";
"~b" = "moveWordBackward:";
"~u" = "pageUp:";
}
Now ,option+f/b can used as my jetbrains IDEs shortcut,but option+u still print special character.
I have found a way: if I select Unicode Hex Input as my input source from System preferences->keyBoard->Input Sources, all bindings now disappeared!

OllyDbg 2.01 - Finding a command referencing a static string

I've taken up cracking and reverse-engineering recently with the help of OllyDbg 2.01 and crackmes executables.
So in this particular crackme, I was scrolling through the commands and noticed a PUSH with an ASCII string "&File" (it's a menu string) :
So I thought : "If I can find this information by simply scrolling, surely there must be an automatic way to find a command referencing a particular string".
So I get to the top of the program, hit CTRL+B and search for ASCII "File" to hopefully find it again :
After hitting OK, OllyDbg doesn't find the earlier PUSH. Instead, I get this :
Mmmh.. Okay, that's not what I expected, but let's see what's in there. so I right click => Follow in Dump, and I get this :
So yeah, we found our string in the dump. However, I still haven't found my original PUSH. You can also notice that the string's address is the same as the PUSH's argument (40512C).
As a last try, I right click on the letter at address 40512C, select "Find References", but nope : no reference found.
So TL ; DR question : how do I automatically find a command referencing a string ? Because obviously I'm not gonna scroll the whole command stack everytime I want to find a string.
PS : the string doesn't appear in "referenced text strings" either.
Thanks in advance for your help.
EDIT : okay so I found a solution. I searched the code for "2C 51 40 00" which is the address backward, and i found my PUSH again. It's a bit hacky, anyone with a more efficient solution is welcome to share.
So, there are multiple ways to do this. What I prefer is the following :
Ctrl+G and go to your string in the dump. (0x0040512C) Select the first byte and hit Ctrl+R. This will give you a list where the particular string is referenced. You could also place a hardware breakpoint on the first byte of the string "&" and then you will break every time something accesses it. You could also search for constants (the address or the ascii characters themselves).
By the way there is a subsite dedicated for reverseengineering :)

mac keyboard function keys mapping

I lost my configuration or never had it.
I need to send shift+F1 and ctrl+F1, shift+F2 and ctrl+F2 and so on to the terminal since I'm connecting to a linux machine via ssh.
well, my current config is missing these string mappings as you can see in the image.
do you know what are the string mappings for those key combinations ?
thanks.
UPDATE:
in some stackexchange i found this command:
$>for x in {1..12}; do echo -n "F$x "; tput kf$x | cat -A; echo; done
can you help me to print the strings for shift + f1 ?
First: From this page http://invisible-island.net/xterm/xterm.faq.html, you will understand that shift-F1 maps to F11, shift-F2 maps to F12 and so on.(Search the page 'a summary of the keyboard mapping' without ', you will see the list).
Second: From this page http://aperiodic.net/phil/archives/Geekery/term-function-keys.html, you will know F1 or F11 or F20 maps to what string(at the bottom).
More to say:
If you want to send Shift-F1 to a program through Terminal, these will happen:
You hit Shift-F1, the Terminal will translate the Shift-F1 to a string sequence
The string sequence will be sent to the program
For example, you send a Shift-F1 to emacs through the Terminal,the Terminal translate it into string sequence and send the string sequence to emacs, emacs will recognise it as a key strokes then do something.
I'm not quite familiar about this, so this answer may be not right.

In OS X (lion) how can I find whether a key combination is in use as a keyboard shortcut?

I want to put a bunch of keyboard shortcuts in my app (OS X lion) so I can do most things from the keyboard. There are of course a bunch of lists of hot key combos in use already, including the one in the HIG.
Is there some utility that can be used to type a key combination and find out if it already means something (either globally, or mac standard -- I'm not too worried about reusing some special combo used by another app -- or should I be?)?
You can use Carbon to do this. Don't be afraid to use Carbon here, there is no Cocoa way to get this information and the Carbon methods are still supported.
The CopySymbolicHotKeys() function returns an array of dictionaries, containing information about the system-wide symbolic hot keys defined in the Keyboard preferences pane. Each dictionary contains information about a single hot key.
Specifically, each dictionary has three keys:
kHISymbolicHotKeyCode: The virtual key code of the hot key, represented as a CFNumber.
kHISymbolicHotKeyModifiers: The hot key’s keyboard modifiers, represented as a CFNumber.
kHISymbolicHotKeyEnabled: The enabled state of the hot key, represented as a CFBoolean.
Obviously these are raw key codes so you will need to do some work if you want to see what the key codes actually refer to.
Note that the array doesn't contain custom, application-specific hotkeys, but this is a minor problem.
Here's a simple example:
#import <Carbon/Carbon.h>
CFArrayRef registeredHotKeys;
if(CopySymbolicHotKeys(&registeredHotKeys) == noErr)
{
CFIndex count = CFArrayGetCount(registeredHotKeys);
for(CFIndex i = 0; i < count; i++)
{
CFDictionaryRef hotKeyInfo = CFArrayGetValueAtIndex(registeredHotKeys, i);
CFNumberRef hotKeyCode = CFDictionaryGetValue(hotKeyInfo, kHISymbolicHotKeyCode);
CFNumberRef hotKeyModifiers = CFDictionaryGetValue(hotKeyInfo, kHISymbolicHotKeyModifiers);
CFBooleanRef hotKeyEnabled = CFDictionaryGetValue(hotKeyInfo, kHISymbolicHotKeyEnabled);
NSLog(#"key code: %# modifiers: %# enabled: %#", hotKeyCode, hotKeyModifiers, hotKeyEnabled);
}
//you MUST release the dictionary when finished with it
CFRelease(registeredHotKeys);
}
Remember that you'll need to add the Carbon framework to the Link Binary with Libraries build phase in your project settings.
For more information you should look at the Carbon Event Manager docs (11Mb PDF).
Thear used to be an API in Carbon to get the global keyboard shortcuts, however, I do not believe there is a Cocoa API for this. I don't think you should worry about other third party apps, but you could refer to http://support.apple.com/kb/HT1343 and just hard code to avoid those. He that helps.

Remap Capslock Key in Keymando?

Can you remap the CapsLock key in Keymando?
CapsLock is listed as an available key but when I try a test like:
map "<CapsLock-j>" { alert("CapsLock-j") }
... and hit Reload Config in the Keymando menu, I get an error dialog that says:
Error Parsing Keymando Config File
undefined method `ctrl' for nil:NilClass
Is there perhaps an abbreviation of CapsLock? For example, in the available keys, the Control key is just listed as Control but in the example code it is ctrl. Is there a similar abbreviation for CapsLock?
If possible, I would like to use the CapsLock key as a mode key to implement logic like:
if <CapsLock>
map <j>, <Down>
map <k>, <Up>
# ...etc
end
Sorry, that's a mistake on our part listing Capslock on the website. Currently it can only be remapped to Control, Option, or Command via the Keyboard.prefPane under "Modifer Keys.." and there's no way for us right now to detect if it's been pressed.
We'll keep our eyes open for a solution but as of right now it's not going to do what you're wanting. Sorry.
The website has been fixed to avoid any more confusion, as well.
While you can't remap capslock, you can achieve almost the same functionality by adding some basic state to your keymandorc file. I couldn't figure out how to map something to the option key alone, but apart from that, this should do what you are aiming for:
At the top of your keymandorc put:
#caps = false
Then down wherever you define your bindings put something like the following
map "j" do
if #caps then
send("<Down>")
else
send("j")
end
end
map "<Option-v>" do
#caps = !#caps;
alert("Vim Mode: " + #caps.to_s)
end
You could then also bind escape to exit the mode if #caps is true, and so forth.

Resources