Autohotkey - AltGr hotkey behaves differently from LAlt hotkey - keyboard-shortcuts

I'm trying to map LAlt+Space to Delete and AltGr+Space to Backspace, so i made this script :
<!Space::Delete
<^>!Space::Backspace
LAlt+Space gets mapped correctly to Delete, but AltGr+Space doesn't work properly : it removes words like Ctrl+Backspace would do instead of removing one character at a time.
I switched 'Delete' and 'Backspace' and got the same issue : LAlt+Space works properly but AltGr+Space removes words like Ctrl+Delete instead of characters.
I'm guessing this might have to do with the fact that AltGr is actually Ctrl+RAlt, so the Ctrl might be composed with Backspace or Delete at some point ?
Does anybody know what the cause of this could be, and a solution ?

While #user3419297's answer is essentially correct, it's advisable in modern versions of AHK to use SendInput over Send.
<!Space::
SendInput, {Delete}
return
<^>!Space::
SendInput, {Backspace}
return

Related

What're the key codes for "Alt+Q Alt+Q"?

I want to create a script that triggers when pressing Q twice while holding Alt, but couldn't figure out what're the correct key codes for that, could someone please shed some light?
P.S. I want to bind this shortcut to Ctrl+F12, which I assigned Sogou IME to turn on the Chinese input mode.
I didn't test this and there's probably a more concise way to do it, but I think something like this should work.
!Q::
If(keyPressed = 1){
...Do a thing...
}
keyPressed := 1
SetTimer, altQTimer, 50
return
altQTimer:
keyPressed := 0
return
TL;DR
In conclusion, even if I do all kinds of hacks and get the script working as intended, it's likely to break in the future, which is really not worth the trouble.
After hours of experimenting, the current conclusion is Sogou IME which uses Ctrl+F12 won't trigger the bound action i.e. switching to the Chinese input mode if it was sent by Alt+[Any Other Key], it can be triggered if it was sent by other shortcuts such as Ctrl+C, which is really unfortunate.
And the weirdest thing is the following code works:
^c::Send !q
!q::Send ^{F12}
And to rule out the potential extra simulated keystrokes (Ctrl by default) effect, the following code also works:
^!q::Send ^{F12}
But the following doesn't (tested on several machines):
!q::Send ^{F12}
Update
After much effort, I did get Alt+Q to turn on the Chinese input mode with the following code, not sure why:
!q::Send ^{F6}
^F6::Send ^{F7}
^F7::Send ^{F12}
But because I also need to trigger a VSCode command using Alt+Q at the same time, I had to modify the above code to the following:
~!q::Send ^{F6} ; with ~ prefixed
^F6::Send ^{F7}
^F7::Send ^{F12}
Now Alt+Q does trigger the VSCode command, but it won't turn on the Chinese input mode...
At last, if I take a step back and bind the VSCode command to Ctrl+C (which could turn on the Chinese input mode with just ^c::Send ^{F12}), I still have to prefix ^c with ~, otherwise it won't trigger the VSCode command, now I'm repeating the cycle all over again...
After all of these attempts, I have to say Sogou IME's logic for determining whether to enable the Chinese input mode is quite indeterminate, making the script for enabling the Chinese input mode very unreliable.
In conclusion, even if I do all kinds of hacks and get the script working as intended, it's likely to break in the future, which is really not worth the trouble.

VIM equivalent of IntelliJ's expand/shrink selection?

How would one achieve the same result. I believe the keybinding for macOS Intellij is op+up/down and on windows it is alt+w/d.
Essentially the function highlights the current word, then, with successive presses, expands out to the full string/line/area in-between parenthesis/further out to the next set of parenthesis. Very useful for developing in LISP.
The closest I've gotten is this: https://vi.stackexchange.com/a/19028
Try this plug in: https://github.com/terryma/vim-expand-region
It expands selections based on Vim’s text objects.
Well this may seem comfortable but does not correspondent with the internal logic of vim itself.
See, in vim everything you enter is like a sentence. va{ for example: there is a verb v -> visually select and an object (or movement) { -> paragraph. In this case there is also a modifier a around. You can exchange stuff in this sentence and it will still work vaw, dil, cB and so on. The power of vim is greatly based on that concept.
Of course you can write a function that does vaw first, then S-v and lastly va{ but that will only work with visual selection. It will not work with c or d or anything. So I will recommend to get used to use different keys for different actions.
The visual selection is mostly not needed anyway. Change a paragraph? directly use ca} and so on.
I have found that VI/VA + WOBO (as many times as you need to expand) works similarly. Not as fast but its the same concept and you can even expand/shrink asymmetrically based on your WO's and BO's (Or OW's and OB's depending on how you look at it)

Pharo: customizing smart characters

The checkbox "Smart Characters" in "Code Completion" section of Settings Browser does (at least) two things:
1) It doubles some characters when typed: ', ", (, [, {
2) It enables that I can select a piece of code, press ( (i.e. Shift+9), and the selected code becomes surrounded by parentheses: (). I also can remove parentheses by pressing ( again. I also can do this with [] by pressing [ and with {} by pressing {, i.e. Shift+[.
I do not like the first of these things so I want to disable it, but I like the second thing and want to keep it. How can I achieve this? Turning off the checkbox will disable both.
P.S. I know that when the checkbox is off, adding/removing parentheses works by Cmd+Shift+9 (which is less convenient than Shift+9) and that Cmd+[ works for [], although I do not know any working shortcut for adding/removing {} when the checkbox is off.
The setting is called "Smart Characters", which should give you a clue as to where to look. Open a Finder, type in smartCharacters, and hit Enter. You should see some partial matches as well as an exact match for NECController and NECPreferences class (and the former just calls the latter). If you investigate the classes involved a bit, you'll see that smartCharacters stores a boolean, and that smartCharactersMapping returns a dictionary mapping some characters to their "counterparts", i.e. $[ to $] and so on. Now look at senders of smartCharactersMapping, and you'll see where it's being called from.
The caller you're most likely interested in would be NECController>>smartCharacterWithEvent. So put a breakpoint in that very ugly method to see what it does. You don't care about the first two cases (the editor having a selection and there not being a smart mapping), since you want to prevent the second matching character from being inserted. So the interesting bit for you is this bit:
self newSmartCharacterInsertionStringForLeft: char right: opposite
The method only has one implementor and that one sender, so it should be safe to comment out the original method and just return the "left" character, i.e.:
newSmartCharacterInsertionStringForLeft: left right: right
^String with: left
In other words, instead of creating a string with the left and right characters, and possibly spaces between them, just return a new string with the single character you typed. Might not be the most elegant way of solving this, but it should work, and should show you how to solve similar problems in the future.
(Ideally, you'll find a better solution, post it here as an alternate answer, and contribute it to the Pharo codebase - Pharo is open source, after all.)

Win->Alt key remapping in AutoHotKey can not work well

I wrote a AutoHotKey script to remap LWin to LAlt
LWin::LAlt
LWin & Tab::AltTab
LWin+Tab works OK. But I found, for example in my emacs, LWin+b can not work as Alt+b. And if I disable this statment
LWin & Tab::AltTab
LWin+b works. But I know LWin+Tab will not works very good without this remapping statement as mentioned in AutoHotKey Remapping.
I'm not entirely sure why, but it seems the first key mapped can only be declared once. I have found a solution (although not perfect) of writing the second command as so: Tab & LWin::AltTab. This means that you have to hold Tab down first though.

execCommand insertHTML inserting multiple times

I am working on a small RTE in a contentEditable DIV. I have attached a keypress event handler to the DIV that monitors when the ENTER key is struck and where the selection is. If it is inside a text node, I am inserting a new line. However, this code is buggy and often inserts 4 newlines instead of one (I have to press undo 4 times to get back to where the cursor was before - that's why I think execCommand is firing multiple times). On the other hand, it sometimes requires TWO strikes of the ENTER key to get a new line inserted.
here is a code snippet of the keypress event handler, once it's determined that the ENTER key has been pressed:
if(selection.focusNode.nodeType!=3){ return; }
ev.preventDefault();
var HTML='
';
toolbar.target.ownerDocument.execCommand('insertHTML',false,HTML);
I want to use execCommand to preserve the browser's undo behavior. I do NOT want to insert a <br> as this insertion only happens in a text node and for post-processing purposes, I need \n in the text nodes instead of <br>'s or any other block-type tags. I am using the unicode newline character
. I have tried the carriage return character 
 as well with similar results. I can't use \n with insertHTML because that is not proper HTML.
Anyone have ideas about how to make sure that execCommand runs ONLY once?