Replacing 3-key hotkey. Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
User avatar
WashingtonD
Posts: 3
Joined: 16 May 2022, 09:59
Contact:

Replacing 3-key hotkey.

Post by WashingtonD » 16 May 2022, 10:16

Because of unworking keys on my keyboard, I'm trying to create NumPad numbers combinations using AHK in order to replace the actions of those keys.
In my idea all the combinations are going to look like Num0 + Num X (where x є [1,9]) and it's working fine, but bacause of limited number of such combinations to get capital letters
I wanted to check if shift is pressed and then decide what letter is sent. Also I'm using a few languages, so I'm checking the keyboard layout.

So the problem is that I cannot check if shift is pressed and get the "Num0 + Num1" combination work in the right way.
I'm attaching code, that I was using.

P.S. I`m new at scripting, I`m still learning and I believe that some of you can help me solve this problem.

Code: Select all

#If GetKeyboardLanguage(WinExist("A")) = 0x0422 or GetKeyboardLanguage(WinExist("A")) = 0x0419

		Numpad0 & Numpad1::
			if GetKeyState("Shift","p")
				Send, З ; That's not three, but cyrylic letter placed at the "P" key.
			else
				send, з
		return
#If

Numpad0 & Numpad1::send, p

GetKeyboardLanguage(_hWnd=0)
{
	if !_hWnd
		ThreadId=0
	else
		if !ThreadId := DllCall("user32.dll\GetWindowThreadProcessId", "Ptr", _hWnd, "UInt", 0, "UInt")
			return false
	if !KBLayout := DllCall("user32.dll\GetKeyboardLayout", "UInt", ThreadId, "UInt")
		return false
	return KBLayout & 0xFFFF
}

User avatar
mikeyww
Posts: 26611
Joined: 09 Sep 2014, 18:38

Re: Replacing 3-key hotkey.

Post by mikeyww » 16 May 2022, 11:04

I do not have an answer but have a clue. Shifted Numpad keys are tricky because the key names actually change, one could say. See https://www.autohotkey.com/docs/KeyList.htm#numpad.

You can use this information to identify a shifted Numpad key press, but I was not able to identify the second key when the first was being held. Others here may know a way, or you may discover a way through some experimentation with this.

If you examine your KeyHistory, it might also provide some clues that lead you to the answer.

The following worked with keys in sequence rather than together. It may give you some ideas.

Code: Select all

NumpadIns::
SoundBeep, 1500
Input, key, L1, {NumpadEnd}
ToolTip, #%key%# #%ErrorLevel%#
If (key = "")
 Send x
Return

Rohwedder
Posts: 7558
Joined: 04 Jun 2014, 08:33
Location: Germany

Re: Replacing 3-key hotkey.

Post by Rohwedder » 16 May 2022, 11:28

Hallo,
try:

Code: Select all

#If GetKeyboardLanguage(WinExist("A")) = 0x0422 or GetKeyboardLanguage(WinExist("A")) = 0x0419

		Numpad0 & Numpad1::
		NumpadIns & NumpadEnd::
			if GetKeyState("Shift","p")
				Send, З ; That's not three, but cyrylic letter placed at the "P" key.
			else
				send, з
		return
#If
Numpad0 & Numpad1::
NumpadIns & NumpadEnd::send, p

GetKeyboardLanguage(_hWnd=0)
{
	if !_hWnd
		ThreadId=0
	else
		if !ThreadId := DllCall("user32.dll\GetWindowThreadProcessId", "Ptr", _hWnd, "UInt", 0, "UInt")
			return false
	if !KBLayout := DllCall("user32.dll\GetKeyboardLayout", "UInt", ThreadId, "UInt")
		return false
	return KBLayout & 0xFFFF
}

User avatar
WashingtonD
Posts: 3
Joined: 16 May 2022, 09:59
Contact:

Re: Replacing 3-key hotkey.

Post by WashingtonD » 16 May 2022, 11:38

mikeyww wrote:
16 May 2022, 11:04
I do not have an answer but have a clue. Shifted Numpad keys are tricky because the key names actually change, one could say. See https://www.autohotkey.com/docs/KeyList.htm#numpad.

You can use this information to identify a shifted Numpad key press, but I was not able to identify the second key when the first was being held. Others here may know a way, or you may discover a way through some experimentation with this.

If you examine your KeyHistory, it might also provide some clues that lead you to the answer.

The following worked with keys in sequence rather than together. It may give you some ideas.

Code: Select all

NumpadIns::
SoundBeep, 1500
Input, key, L1, {NumpadEnd}
ToolTip, #%key%# #%ErrorLevel%#
If (key = "")
 Send x
Return
Thanks, I've tried your solution and it works as it should, but colegue above has provided us a more convinient soulution!
Last edited by WashingtonD on 16 May 2022, 11:57, edited 1 time in total.

Rohwedder
Posts: 7558
Joined: 04 Jun 2014, 08:33
Location: Germany

Re: Replacing 3-key hotkey.  Topic is solved

Post by Rohwedder » 16 May 2022, 11:47

Or:

Code: Select all

#If GetKeyboardLanguage(WinExist("A")) = 0x0422 or GetKeyboardLanguage(WinExist("A")) = 0x0419
Numpad0 & Numpad1::Send,% ["з","З"][1+GetKeyState("Shift","p")]
#If
Numpad0 & Numpad1::send, p

GetKeyboardLanguage(_hWnd=0)
{
	if !_hWnd
		ThreadId=0
	else
		if !ThreadId := DllCall("user32.dll\GetWindowThreadProcessId", "Ptr", _hWnd, "UInt", 0, "UInt")
			return false
	if !KBLayout := DllCall("user32.dll\GetKeyboardLayout", "UInt", ThreadId, "UInt")
		return false
	return KBLayout & 0xFFFF
}
#InputLevel, 100
NumpadIns::Numpad0
NumpadEnd::Numpad1
NumpadDown::Numpad2
NumpadPgDn::Numpad3
NumpadLeft::Numpad4
NumpadClear::Numpad5
NumpadRight::Numpad6
NumpadHome::Numpad7
NumpadUp::Numpad8
NumpadPgUp::Numpad9
#InputLevel, 1 ; Now Shift key should no longer affect Numpad0 - Numpad9!

ahk7
Posts: 575
Joined: 06 Nov 2013, 16:35

Re: Replacing 3-key hotkey.

Post by ahk7 » 16 May 2022, 12:00

Not an answer, but perhaps consider an alternative by not pressing two keys at the same time which may be cumbersome, but by typing a number which then sends a key, as you mentioned numpad I was reminded of Thumbscript https://www.autohotkey.com/board/topic/27198-beta-thumbscript-ahk/

So in the script above, typing 13 on the numpad sends 'a' the list is in the script under "BuildList:" label which you can of course easily adapt.

User avatar
WashingtonD
Posts: 3
Joined: 16 May 2022, 09:59
Contact:

Re: Replacing 3-key hotkey.

Post by WashingtonD » 16 May 2022, 12:04

ahk7 wrote:
16 May 2022, 12:00
Not an answer, but perhaps consider an alternative by not pressing two keys at the same time which may be cumbersome, but by typing a number which then sends a key, as you mentioned numpad I was reminded of Thumbscript https://www.autohotkey.com/board/topic/27198-beta-thumbscript-ahk/

So in the script above, typing 13 on the numpad sends 'a' the list is in the script under "BuildList:" label which you can of course easily adapt.
That code looks a little hard for me to analyze, but I`m gonna try. I believe that it is a good alternative solution, thanks!

Post Reply

Return to “Ask for Help (v1)”