Autocompleting parenthesis and placing cursor inbetween Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
AndrewKun
Posts: 24
Joined: 03 Jun 2015, 12:03

Autocompleting parenthesis and placing cursor inbetween

09 Jan 2017, 09:19

Hi,

I'm trying to create an autocompletion script for parenthesis and quotes, like it is done in many IDEs. For example if I double press "<", it should output "<>" and place the cursor in the middle.

Code: Select all

$+<::
	If (A_ThisHotKey = A_PriorHotkey and A_TimeSincePriorHotkey < 300) {
		SendInput >
		Send, {Left}
	}
	else {
		SendInput <
	}
return
The point is to type <> and position cursor in between when I double press the Shift+< key. This works, but the problem is that I use also non-english keyboard layouts, and when I need Shift+< to type non-english character on the same key (russian 'Б' in my case), I also get "<" symbol. I tried to use "Send %A_ThisHotkey%" but it sends "<" anyway, and if I just remove the else statement it doesn't send anything at all.

How can I send the original keypress in the else statement, or bypass the script if the "IF "statement is false? Or maybe there's more elegant solution?
Last edited by AndrewKun on 10 Jan 2017, 01:58, edited 1 time in total.
User avatar
Nextron
Posts: 1391
Joined: 01 Oct 2013, 08:23
Location: Netherlands OS: Win10 AHK: Unicode x32

Re: Issues with sending the original keypress

09 Jan 2017, 16:02

Without having this hotkey, what's AHK's key history when you press Shift+< using either keyboard layout?
AndrewKun
Posts: 24
Joined: 03 Jun 2015, 12:03

Re: Issues with sending the original keypress  Topic is solved

10 Jan 2017, 01:55

Nextron wrote:Without having this hotkey, what's AHK's key history when you press Shift+< using either keyboard layout?
It's the following:
A0 02A d 0.45 LShift
BC 033 h d 0.30 ,
BC 033 i d 0.00 ,
BC 033 i u 0.00 ,
BC 033 s u 0.08 ,
A0 02A u 0.30 LShift

I've tried using VK and SC, but it doesn't help in this case
smarq8 wrote:

Code: Select all

~$+<::
like this?
Actually, this is useful, I did like this

Code: Select all

~$+<::
	If (A_ThisHotKey = A_PriorHotkey and A_TimeSincePriorHotkey < 300) {
		SendInput >
		Send, {Left}
		Send, {Backspace}
	}
return
This way the script deletes extra character when using English Keyboard, and on the russian I don't use double press anyway, so it works. But this is a crude solution, I'm sure it can be solved much better with AHK, because autocompleting different parenthesis and quotes (like { [ " ' e.t.c.) is a very common feature among programmers.

Thank you very much for your suggestion, the scrpit is at least usable now.

UPD: I've modified the opening question to better reflect the task and the problem.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: No registered users and 383 guests