How to input brackets in a mac using a Portuguese PC Keyboard

I’ve bought the new Mac Mini M2! And I don’t have the mac magic keyobard. Nor a monitor specific for the Mac! I wouldn’t wanna spend 100 bucks to get the quirks for the mac stuff. I wanna reuse my old keyboards put aside. The problem is… they’re all PC Keyboards! Yes, I know, Option Key can be used as the Alt key modifier, and the Cmd Key can be used as the Windows (forget the publicity!) key. Problem is… Not everything works well. In my specific case, since I am portuguese, the brackets keys ({}) doesn’t appear in the portuguese mac Keyboard, you have to use the combination Shift+Cmd+7 to input { and Shift+Cmd+0 to input }. In a PC Keyboard, is RightAlt+7 and RightAlt+0. Strangely, plugging in a PC keyoard in the mac, RightAlt+8 and RightAlt+9 outputs square parentesis ([ and ]) works but to input brackets does not. If I were in Windows, I would use AutoHotkey to achieve this. But in the mac, there is a similar alternative, Hammerspoon ! which uses Lua as the language. This language is starightforward to learn, and after much trials and attempts, I’ve managed to achieve to Use Ctrl+C and Ctrl+V to work on the mac, using the following code:

-- remap copy+paste to ctrl+c and ctrl+v
hs.hotkey.bind({"ctrl"}, "c", nil, function()"COPY!")
    hs.eventtap.keyStroke({"cmd"}, "c")

hs.hotkey.bind({"ctrl"}, "v", nil, function()"PASTE!")
    hs.eventtap.keyStroke({"cmd"}, "v")

And that does the work, but to enter the brackets I had to fight to understand more ! I have found that the function hs.eventtap.keyStroke could be used to achieve the effect, the problem is that keycode for the left bracket falls in the number above 255 (ie, is not in the ASCII table), and does not a map to a single discrete integer value. So, there was a solution use the function hs.eventtap.keyStrokes which outputs an entire string when called.
This way, I achieved my objectives with the follwing functions:

hs.hotkey.bind({"rightalt"},"7", nil,function ()

hs.hotkey.bind({"rightalt"},"0", nil,function ()

Next job will be to remap the characters which respective keys are in a different positions in the mac keyboard. Characters like \|+* in order to reuse the complete PC keyboard in a mac!




Social Media Auto Publish Powered By :
%d bloggers like this: