 |
AutoHotkey Community Let's help each other out
|
| View previous topic :: View next topic |
| Author |
Message |
sashabe
Joined: 09 Oct 2006 Posts: 14
|
Posted: Sun Aug 12, 2007 8:39 pm Post subject: Toggle "Always Run" mode with Caps Lock |
|
|
I'm trying to set up Capslock behaviour so when it's "on", the "w" key (most known as a "go forward" key in PC games) pressed once produces permanent effect as if it were down, and repeated keystroke returns it to normal behaviour. When Capslock is "off", the "w" behaves in a normal way. Like in Oblivion, it seems. Smthg like this script doesn't work:
| Code: | ^c::
If CapsON()
{
Send {w DOWN}
SetKeyDelay, 0, 10, Play
}
Return
CapsON()
{
Return GetKeyState("CapsLock", "T")
} |
How can i do this? |
|
| Back to top |
|
 |
tonne
Joined: 06 Jun 2006 Posts: 1159 Location: Denmark
|
Posted: Sun Aug 12, 2007 9:20 pm Post subject: |
|
|
From the help file:
| Quote: | | When a key is held down via the method above, it does not begin auto-repeating like it would if you were physically holding it down (this is because auto-repeat is a driver/hardware feature). However, a Loop can be used to simulate auto-repeat. The following example sends 20 tab keystrokes: |
An example (also from the help file):
| Code: | Loop 20
{
Send {Tab down} ; Auto-repeat consists of consecutive down-events (with no up-events).
Sleep 30 ; The number of milliseconds between keystrokes (or use SetKeyDelay).
Send {Tab up} ; Release the key. |
This might work:
| Code: | $w::
if GetKeyState("CapsLock", "T")
{
loop
{
Send {w down}
sleep 250
if !GetKeyState("CapsLock", "T")
break
}
Send {w up}
}
else
send w
return |
_________________ there's a dog barking close within the range of my ear
sounds like he wants to escape the chain
he would probably bite me to death if he could
but the chain lets me spit in his face
- Kashmir |
|
| Back to top |
|
 |
sashabe
Joined: 09 Oct 2006 Posts: 14
|
Posted: Mon Aug 13, 2007 1:43 am Post subject: |
|
|
Thanks, it works as needed, but not in game (Far Cry). The single "w" stops working. I tried the following variant (as it may be more compatible with games as i've understood), but it just disables both keystrokes in-game, single-pressed and continuous:
| Code: | $w::
if GetKeyState("CapsLock", "T")
{
loop
{
SendPlay {w down}
SetKeyDelay, 0, 0, Play
if !GetKeyState("CapsLock", "T")
break
}
SendPlay {w up}
}
else
send w
return
|
|
|
| Back to top |
|
 |
sashabe
Joined: 09 Oct 2006 Posts: 14
|
Posted: Tue Aug 14, 2007 9:52 am Post subject: |
|
|
After a number of tests, this code works (WOHOO!! :
| Code: | ~w::
if GetKeyState("CapsLock", "T")
{
loop
{
Send {w down}
sleep 250
if !GetKeyState("CapsLock", "T")
break
}
Send {w up}
}
return |
Just needed to replace & with ~ in hotkey and remove "else" expression. Anyway, thanks a lot for the help) |
|
| Back to top |
|
 |
|
|
You can post new topics in this forum You can reply to topics in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|