About alernative Win Key Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Scrap
Posts: 6
Joined: 18 Dec 2021, 06:45

About alernative Win Key

Post by Scrap » 13 Jan 2022, 12:12

A few months ago, I made a forum post asking for help about implementing a windows key replacement solution. However, the solution did not work well for the Win+1 emulation. When the first application in the taskbar has multiple windows, if I hold down the Win key and then press 1 multiple times, I should be able to switch between them(Like alt+tab). If the script is implemented with multiple Win+1, it does not work correctly.

In general, I want to achieve the following functionality.
1. when I press ` and other keys, the ` key acts as LWin key.
2. If I press the ` key alone, enter `.

Code: Select all

#InstallKeybdHook

`::
state := GetKeyState("~")
pressed := 0
Loop{
	state := GetKeyState("~")
	key := A_PriorKey
	if (key != "``" And key != ""){
		if (pressed == 0){
			Send {LWin Down}
			pressed := 1
		}
		Send, %key%
		key := ""
	}
	if (state==0){
		break
	}
}
if (pressed == 0){
	SendRaw ``
}else{
	Send {LWin Up}
}
Return
I tried to implement it with the above code, but it behaves weirdly and doesn't type ` properly and will type the key combination I pressed. Can someone give me a solution?
Thank you.

amateur+
Posts: 655
Joined: 09 Oct 2021, 15:43

Re: About alernative Win Key

Post by amateur+ » 13 Jan 2022, 14:41

Code: Select all

sc29::LWin
^sc29::send {vkC0} ; or !sc29::send {vkC0} for Alt+`
+sc29::send ~
Just use Ctrl + ` to send `.
You can also send usual ` by pressing simultaneously d+f+j+k with this code:

Code: Select all

#if AllPressed("d f j k")
d::
f::
j::
k::
SendInput, +{Left 3}{Delete}{vkC0}
KeyWait, % A_ThisHotkey
return
#if

AllPressed(pStr) {
	Loop, Parse, pStr, %A_Space%
		if !GetKeyState(A_LoopField, "P")
			return 0
	return 1
}	

sc29::LWin
^sc29::send {vkC0} ; or !sc29::send {vkC0} for Alt+`
+sc29::send ~
Have found any drawback in my code or approach? Please, point it out. /The moderator ordered to remove the rest of the signature, I had obeyed.
And I really apologize for our russian president. Being a citizen of an aggressor country is very shameful. Personally I tried to avoid this trying to defend elections from fraud being a member of the election commission of one of the precincts but only was subjected to a hooligan attack and right before the vote count was illegally escorted from the polling station and spent the night behind bars (in jail) in a result of illegal actions of corrupt policemen.

Scrap
Posts: 6
Joined: 18 Dec 2021, 06:45

Re: About alernative Win Key

Post by Scrap » 15 Jan 2022, 22:30

amateur+ wrote:
13 Jan 2022, 14:41

Code: Select all

sc29::LWin
^sc29::send {vkC0} ; or !sc29::send {vkC0} for Alt+`
+sc29::send ~
Just use Ctrl + ` to send `.
You can also send usual ` by pressing simultaneously d+f+j+k with this code:

Code: Select all

#if AllPressed("d f j k")
d::
f::
j::
k::
SendInput, +{Left 3}{Delete}{vkC0}
KeyWait, % A_ThisHotkey
return
#if

AllPressed(pStr) {
	Loop, Parse, pStr, %A_Space%
		if !GetKeyState(A_LoopField, "P")
			return 0
	return 1
}	

sc29::LWin
^sc29::send {vkC0} ; or !sc29::send {vkC0} for Alt+`
+sc29::send ~
Thanks, that's an acceptable solution.
But I'd still like to implement my original functionality if possible.

amateur+
Posts: 655
Joined: 09 Oct 2021, 15:43

Re: About alernative Win Key

Post by amateur+ » 17 Jan 2022, 18:34

Have killed almost two hours on your task.

Code: Select all

$vkC0::
SetKeyDelay -1   
Send {LWin Down} 
return

#vkC0::return

#vkC0 up::
vkC0 up::
SetKeyDelay -1 
if (A_PriorKey = "``")
	Send {Esc}{LWin up}{vkC0}
else Send {LWin up}
return
Have found any drawback in my code or approach? Please, point it out. /The moderator ordered to remove the rest of the signature, I had obeyed.
And I really apologize for our russian president. Being a citizen of an aggressor country is very shameful. Personally I tried to avoid this trying to defend elections from fraud being a member of the election commission of one of the precincts but only was subjected to a hooligan attack and right before the vote count was illegally escorted from the polling station and spent the night behind bars (in jail) in a result of illegal actions of corrupt policemen.

Scrap
Posts: 6
Joined: 18 Dec 2021, 06:45

Re: About alernative Win Key

Post by Scrap » 21 Jan 2022, 13:56

amateur+ wrote:
17 Jan 2022, 18:34
Have killed almost two hours on your task.

Code: Select all

$vkC0::
SetKeyDelay -1   
Send {LWin Down} 
return

#vkC0::return

#vkC0 up::
vkC0 up::
SetKeyDelay -1 
if (A_PriorKey = "``")
	Send {Esc}{LWin up}{vkC0}
else Send {LWin up}
return
I apologize that it took me so many days to respond.
Thank you very much for the code and the time you put in.
In the vast majority of cases, this code works fine. However, when the ` key is pressed alone, you cancel the previously pressed LWin via the ESC key, which is a more subtle way to do it, but it also makes the ESC key be entered in.
For example, when typing ` in cmd, it triggers the ESC key, causing the current line of typed text to be cleared. In some games, it can cause similar trouble.
So my previous code tried to make sure that ` was triggering LWin when pressed along with another key.
I tried to change my previous code. Now my code works fine in most cases. However, there is a flaw: when I press ` and another key, that key gets keyed in. Do you have any suggestions?

Code: Select all

#InstallKeybdHook

$`::
SetKeyDelay -1
state := GetKeyState("``","P")
triggered := 0
new_trigger := 0
Loop{
	state := GetKeyState("``","P")
	if (state = 0){
		break
	}
	key := A_PriorKey
	if (key = "" Or key = "``"){
		new_trigger := 1
	}
	if (key != "``" And key != "" And new_trigger = 1){
		key_holding := GetKeyState(key,"P")
		if (triggered =0){
			Send {LWin Down}
			sleep 50
			if (key_holding = 0){
				Send {%key%}
			}
			triggered := 1
		}
	}
}

if (triggered = 0){
	Send {vkC0}
}else{
	Send {LWin Up}
}
Return

amateur+
Posts: 655
Joined: 09 Oct 2021, 15:43

Re: About alernative Win Key  Topic is solved

Post by amateur+ » 21 Jan 2022, 22:55

Code: Select all

$vkC0::
SetKeyDelay -1   
Send {LWin Down}
return

#vkC0::return
#vkC0 up::
vkC0 up::
SetKeyDelay -1 
if (A_PriorKey = "``")
	Send {vkFF}{LWin up}{vkC0}
else Send {LWin up}
return
Have found any drawback in my code or approach? Please, point it out. /The moderator ordered to remove the rest of the signature, I had obeyed.
And I really apologize for our russian president. Being a citizen of an aggressor country is very shameful. Personally I tried to avoid this trying to defend elections from fraud being a member of the election commission of one of the precincts but only was subjected to a hooligan attack and right before the vote count was illegally escorted from the polling station and spent the night behind bars (in jail) in a result of illegal actions of corrupt policemen.

Scrap
Posts: 6
Joined: 18 Dec 2021, 06:45

Re: About alernative Win Key

Post by Scrap » 21 Jan 2022, 23:58

amateur+ wrote:
21 Jan 2022, 22:55

Code: Select all

$vkC0::
SetKeyDelay -1   
Send {LWin Down}
return

#vkC0::return
#vkC0 up::
vkC0 up::
SetKeyDelay -1 
if (A_PriorKey = "``")
	Send {vkFF}{LWin up}{vkC0}
else Send {LWin up}
return
This works very well.
Thank you very much.

amateur+
Posts: 655
Joined: 09 Oct 2021, 15:43

Re: About alernative Win Key

Post by amateur+ » 22 Jan 2022, 07:04

You're welcome!
Have found any drawback in my code or approach? Please, point it out. /The moderator ordered to remove the rest of the signature, I had obeyed.
And I really apologize for our russian president. Being a citizen of an aggressor country is very shameful. Personally I tried to avoid this trying to defend elections from fraud being a member of the election commission of one of the precincts but only was subjected to a hooligan attack and right before the vote count was illegally escorted from the polling station and spent the night behind bars (in jail) in a result of illegal actions of corrupt policemen.

Post Reply

Return to “Ask for Help (v1)”