AutoHotkey Community

It is currently May 25th, 2012, 2:41 pm

All times are UTC [ DST ]




Post new topic Reply to topic  [ 4 posts ] 
Author Message
PostPosted: August 12th, 2007, 8:39 pm 
Offline

Joined: October 9th, 2006, 9:27 am
Posts: 21
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?


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 12th, 2007, 9:20 pm 
Offline

Joined: June 6th, 2006, 3:19 pm
Posts: 1654
Location: Denmark
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

_________________
RegEx Powered Dynamic Hotstrings
COM
AutoHotkey 2


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 13th, 2007, 1:43 am 
Offline

Joined: October 9th, 2006, 9:27 am
Posts: 21
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


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 14th, 2007, 9:52 am 
Offline

Joined: October 9th, 2006, 9:27 am
Posts: 21
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)


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: BrandonHotkey, Exabot [Bot], Google Feedfetcher, Pulover, Sambo, sarevok9, Wicked, Yahoo [Bot] and 14 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group