-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adding unicode modifications #697
Comments
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
Anything on this? I haven't figured out if there is an answer. |
I don't know of any native way Karabiner could do this, but you could take a look at setting your Input Source to Unicode Hex Input in your Keyboard Preferences. That allows you to type unicode characters by their number while holding option. And then map option+A to that series of numbers. edit: that works, although you'll have to look up the code for that diamond: {
"title": "Print Unicode Characters",
"maintainers": [
"harmtemolder"
],
"rules": [{
"description": "Print Unicode Characters",
"manipulators": [{
"type": "basic",
"from": {
"key_code": "a"
},
"to": [{
"key_code": "2",
"modifiers": [
"option"
]
},
{
"key_code": "6",
"modifiers": [
"option"
]
},
{
"key_code": "2",
"modifiers": [
"option"
]
},
{
"key_code": "0",
"modifiers": [
"option"
]
}
]
}]
}]
} Maybe start and end with control+space to switch input methods so you're not in Unicode Hex Input at all times? |
Alternatively, use a shell script. Karabiner config: #!/usr/bin/env ruby
#######################################################################
# You can generate json by executing the following command on Terminal.
# ruby ./insert_unicode.json.rb
#######################################################################
require 'json'
MODIFIER = 'fn'
KEY_CODES = ('a' .. 'z').to_a.freeze
def rules
KEY_CODES.map do |key_code|
{
desscription: "Insert Character with Key '#{key_code}'",
manipulators: [{
type: "basic",
from: {
key_code: key_code,
modifiers: {
mandatory: [MODIFIER]
}
},
to: [{
'shell_command': "~/.config/karabiner/assets/complex_modifications/helpers/unicode " + key_code
}],
to_delayed_action: {
to_if_invoked: [
{
key_code: "v",
modifiers: "command"
},
{
"shell_command": "pbpaste -pboard ruler | pbcopy"
}
]
},
parameters: {
'basic.to_delayed_action_delay_milliseconds': 100
}
}]
}
end
end
def main
{
title: 'Insert Unicode Characters',
rules: rules
}
end
puts JSON.pretty_generate(main) You can restrict this to only execute when Shell script (~/.config/karabiner/assets/complex_modifications/helpers/unicode):
For Bash, see https://stackoverflow.com/questions/602912/how-do-you-echo-a-4-digit-unicode-character-in-bash |
@MuhammedZakir Hi, I have a similar problem here, which involves inputting the punctuations that are not on the keyboard. I modify your script a bit but it doesn't work? Would you mind to help me check the reason? Thanks. I have two files:
{
"title": "fn半角符号切换 | Map fn + chinese punctuations to their corresponding halfwidth forms",
"rules": [
{
"description": "Map fn + punctuations to their corresponding halfwidth forms",
"manipulators": [
{
"type": "basic",
"from": {
"key_code": "a",
"modifiers": {
"mandatory": ["fn"]
}
},
"to": [
{
"shell_command": "~/.config/karabiner/assets/complex_modifications/helpers/halfwidth_convert a"
}
]
}
]
}
]
}
Based on my understanding, when I press |
At the end of shell script, to_delayed_action: {
to_if_invoked: [{
key_code: "v",
modifiers: "command"
}]
},
parameters: {
'basic.to_delayed_action_delay_milliseconds': 100
} P.S. Recently, I came across |
Actually I have tried it but failed. My scripts with this part are shown as below:
{
"title": "fn半角符号切换 | Map fn + chinese punctuations to their corresponding halfwidth forms",
"rules": [
{
"description": "Map fn + punctuations to their corresponding halfwidth forms",
"manipulators": [
{
"type": "basic",
"from": {
"key_code": "a",
"modifiers": {
"mandatory": ["fn"]
}
},
"to": [
{
"shell_command": "~/.config/karabiner/assets/complex_modifications/helpers/halfwidth_convert a"
}
],
"to_delayed_action": {
"to_if_invoked": [{
"key_code": "v",
"modifiers": "command"
}]
},
"parameters": {
"basic.to_delayed_action_delay_milliseconds": 100
}
}
]
}
]
}
btw I have tried the shell script itself but fails, too. I'm not familiar with sh so am not sure whether the shell script has a problem. I tried
Thanks for your recommendation. I have similar text-replacement stuff such as Mac built-in text replacement and Alfred 4 script. The reason I use karabiner here is that I prefer inputting the punctuations more quickly, and then they can be switched back automatically and immediately. Text replacement is not that efficient in this case. |
I see! |
I ultimately finish my side-project based on your suggestions. Thanks a lot for your help! Here is probably the last question:
If others download my scripts, do they need to Edit: ok, just figure out that it doesn't work as well as I thought 😂. This mechanism copy the character to the clipboard so it's a bit inconvenient when you want to copy something but at the same time use this script. I'm trying to remove the first item in clipboard history (i.e. the copied character) each time or use another method. But anyway, thanks for your inspiration. |
Congrats! 😄
Permissions can be preserved by downloading zip [1] file.
You are welcome! And... this isn't the end! 😉 Put this before printf function in shell script
and add one more command to delayed action.
This shell command will copy content inside ruler pboard to general pboard. Note: There are four pboards -
See pbcopy or pbpaste manpage for more information. |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
Thanks to harmtemolder's response above, I was able to get Karabiner-Elements to convert keystrokes to both 4-digit (e.g., math symbols) and 5-digit (e.g., emoji) unicode. I didn't have to resort to running a shell script or copy/paste. It's just a complex modification in karabiner.json. Here's my code. The json file generally is structured this way...
And here is an example complex modification that is inserted into the section above for a 4-digit hex unicode (U+03BC for the mu symbol)...
For this to work, it requires that you first go into your Mac System Preferences - Keyboard settings, and add the Unicode Hex input mode. You'll see that in the code above when keypad_1 is pressed, it converts it first to a Ctrl+Spacebar that will switch to the Unicode Hex input mode, and then it "types" Option(held down)+0 3 b c. Then finishes by typing Ctrl+Spacebar to return to your original Mac keyboard input mode. Also note, that I've specified "product_id" and "vendor_id" in the code above to limit the modification to a specific device, a numeric keypad that I'm using. You'll want to either remove this part, or change it to refer the the IDs of the device you're using. I've converted two numeric keypads to a math and an emoji keypads. There's a bit more detail on my website: https://www.edmundseto.com/edmundseto/creating-a-scientific-keypad-for-mac/ Again, thanks to harmtemolder for leading the way for me. |
Is it possible to modify a key's input to Unicode characters not in the default keyboard? For example, if I want to map
left_option
+a
to 💎The text was updated successfully, but these errors were encountered: