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.
Reverse Key Pressing
Re: Reverse Key Pressing
Hallo,
Set CapsLockState on
or try:
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
Sorry, my explanation was misleading. Shift should not be a modifier for P in this script.Rohwedder wrote:Hallo,
Set CapsLockState on
or try:Code: Select all
+p::Send {p DownR} p::Send +{p DownR} *p Up::Send {p Up}
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
I have come up with this so far:
It sends P as down continuously, but Shift doesn't break the loop.
Code: Select all
KeyState := GetKeyState("Shift")
loop{
if (KeyState = 1){
send {p up}
}
else{
send {p down}
}
sleep 20
}
Re: Reverse Key Pressing
Try this:Starker wrote:I have come up with this so far:It sends P as down continuously, but Shift doesn't break the loop.Code: Select all
KeyState := GetKeyState("Shift") loop{ if (KeyState = 1){ send {p up} } else{ send {p down} } sleep 20 }
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
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
Last edited by Onimuru on 25 Sep 2018, 17:53, edited 2 times in total.
Re: Reverse Key Pressing
Code: Select all
#InstallKeybdHook
loop{
KeyState := GetKeyState("Shift")
if (KeyState = 1){
send {p up}
}
else{
send {p down}
}
sleep 20
}
Re: Reverse Key Pressing
Hallo,
try:
try:
Code: Select all
SendInput, {p DownR}
Return
*p::Return
~*Shift::SendInput, {p Up}
~Shift Up::SendInput, {p DownR}
Re: Reverse Key Pressing
Onimuru wrote:Try this:Starker wrote:I have come up with this so far:It sends P as down continuously, but Shift doesn't break the loop.Code: Select all
KeyState := GetKeyState("Shift") loop{ if (KeyState = 1){ send {p up} } else{ send {p down} } sleep 20 }
And to tie it to a window: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
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
This crashes instantly when run.Rohwedder wrote:Hallo,
try:Code: Select all
SendInput, {p DownR} Return *p::Return ~*Shift::SendInput, {p Up} ~Shift Up::SendInput, {p DownR}
Re: Reverse Key Pressing
This also crashes instantly.swagfag wrote:Code: Select all
#InstallKeybdHook loop{ KeyState := GetKeyState("Shift") if (KeyState = 1){ send {p up} } else{ send {p down} } sleep 20 }
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
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.
Who is online
Users browsing this forum: No registered users and 65 guests