Page 1 of 1
Reverse Key Pressing
Posted: 20 Sep 2018, 16:33
by Starker
I am trying to make a script that:
- Sends the P (or any key) key as held down when the physical state of the Shift key is up
- Sends the P key as up when the physical state of the Shift key is held down.
- Essentially, I need script that reverses the function of the shift key.
There is no toggle in the script.
Re: Reverse Key Pressing
Posted: 22 Sep 2018, 04:35
by Rohwedder
Hallo,
Set CapsLockState on
or try:
Code: Select all
+p::Send {p DownR}
p::Send +{p DownR}
*p Up::Send {p Up}
Re: Reverse Key Pressing
Posted: 25 Sep 2018, 16:24
by Starker
Rohwedder wrote:Hallo,
Set CapsLockState on
or try:
Code: Select all
+p::Send {p DownR}
p::Send +{p DownR}
*p Up::Send {p Up}
Sorry, my explanation was misleading. Shift should not be a modifier for P in this script.
I am trying to have P sent as held down always unless Shift is held down. Once Shift is released, P returns to the down position.
Re: Reverse Key Pressing
Posted: 25 Sep 2018, 16:30
by Starker
I have come up with this so far:
Code: Select all
KeyState := GetKeyState("Shift")
loop{
if (KeyState = 1){
send {p up}
}
else{
send {p down}
}
sleep 20
}
It sends P as down continuously, but Shift doesn't break the loop.
Re: Reverse Key Pressing
Posted: 25 Sep 2018, 17:33
by Onimuru
Starker wrote:I have come up with this so far:
Code: Select all
KeyState := GetKeyState("Shift")
loop{
if (KeyState = 1){
send {p up}
}
else{
send {p down}
}
sleep 20
}
It sends P as down continuously, but Shift doesn't break the loop.
Try this:
Code: Select all
#SingleInstance Force
SendMode Input
SetTimer, p_L, On
Exit
p_L:
Send {p Down}
Sleep 20
Return
+Esc::ExitApp ;Shift + Escape to exit the script.
$LShift::
SetTimer, p_L, Off
KeyWait, Shift
SetTimer, p_L, On
Return
And to tie it to a window:
Code: Select all
#SingleInstance Force
SendMode Input
SetTimer, p_L, On
Exit
p_L:
If !WinActive("ahk_class Notepad++") ;Change the class here to your game.
WinWaitActive, ahk_class Notepad++
Send {p Down}
Sleep 20
Return
#If WinActive("ahk_class Notepad++")
LShift::
SetTimer, p_L, Off
KeyWait, Shift
SetTimer, p_L, On
Return
#If
+Esc::ExitApp
Re: Reverse Key Pressing
Posted: 25 Sep 2018, 17:39
by swagfag
Code: Select all
#InstallKeybdHook
loop{
KeyState := GetKeyState("Shift")
if (KeyState = 1){
send {p up}
}
else{
send {p down}
}
sleep 20
}
Re: Reverse Key Pressing
Posted: 26 Sep 2018, 00:29
by Rohwedder
Hallo,
try:
Code: Select all
SendInput, {p DownR}
Return
*p::Return
~*Shift::SendInput, {p Up}
~Shift Up::SendInput, {p DownR}
Re: Reverse Key Pressing
Posted: 29 Sep 2018, 19:26
by Starker
Onimuru wrote:Starker wrote:I have come up with this so far:
Code: Select all
KeyState := GetKeyState("Shift")
loop{
if (KeyState = 1){
send {p up}
}
else{
send {p down}
}
sleep 20
}
It sends P as down continuously, but Shift doesn't break the loop.
Try this:
Code: Select all
#SingleInstance Force
SendMode Input
SetTimer, p_L, On
Exit
p_L:
Send {p Down}
Sleep 20
Return
+Esc::ExitApp ;Shift + Escape to exit the script.
$LShift::
SetTimer, p_L, Off
KeyWait, Shift
SetTimer, p_L, On
Return
And to tie it to a window:
Code: Select all
#SingleInstance Force
SendMode Input
SetTimer, p_L, On
Exit
p_L:
If !WinActive("ahk_class Notepad++") ;Change the class here to your game.
WinWaitActive, ahk_class Notepad++
Send {p Down}
Sleep 20
Return
#If WinActive("ahk_class Notepad++")
LShift::
SetTimer, p_L, Off
KeyWait, Shift
SetTimer, p_L, On
Return
#If
+Esc::ExitApp
I am not sure how I am supposed to use this. It appears that it will only run when Sven Co-op is thw active window. To run the script, I must clock out of Sven Co-op, thus Sven Co-op is no longer active and the script instantly closes.
However, I tried just the first block you wrote and that also instantly crashes.
I replaced all "ahk_class" with "Sven Co-op" which is the name of the game's window.
Re: Reverse Key Pressing
Posted: 29 Sep 2018, 19:31
by Starker
Rohwedder wrote:Hallo,
try:
Code: Select all
SendInput, {p DownR}
Return
*p::Return
~*Shift::SendInput, {p Up}
~Shift Up::SendInput, {p DownR}
This crashes instantly when run.
Re: Reverse Key Pressing
Posted: 29 Sep 2018, 19:35
by Starker
swagfag wrote:Code: Select all
#InstallKeybdHook
loop{
KeyState := GetKeyState("Shift")
if (KeyState = 1){
send {p up}
}
else{
send {p down}
}
sleep 20
}
This also crashes instantly.
At the risk of sounding whiney, the scripts given to me by those on the AHK Subreddit actually ran, even though they did not fully function.
Should I expect people to post scripts here without having run them themselves?
Yes, I have reinstalled AHK.
Re: Reverse Key Pressing
Posted: 29 Sep 2018, 19:38
by Onimuru
You need to debug your issue yourself, I tested the code I posted and it works fine. It may be UAC or something. In fact, all the code posted here is good. I'm not sure if you want p to be sent continuously (ppppppppp) or as held down but once you fix the crashing issue you're having, you will find the code you need to achieve what you want in the examples.