diff --git a/docs/Hotkeys.htm b/docs/Hotkeys.htm index e52a2e7c6..d89dcfd7c 100644 --- a/docs/Hotkeys.htm +++ b/docs/Hotkeys.htm @@ -11,7 +11,7 @@ -

Hotkeys (Mouse, Joystick and Keyboard Shortcuts)

+

Hotkeys (Mouse, Controller and Keyboard Shortcuts)

Table of Contents

@@ -126,14 +126,14 @@

Hotkey Modifier Symbols

*LWin Up::Send {LControl up}

"Up" can also be used with normal hotkeys as in this example: ^!r Up::MsgBox You pressed and released Ctrl+Alt+R. It also works with combination hotkeys (e.g. F1 & e Up::)

-

Limitations: 1) "Up" does not work with joystick buttons; and 2) An "Up" hotkey without a normal/down counterpart hotkey will completely take over that key to prevent it from getting stuck down. One way to prevent this is to add a tilde prefix (e.g. ~LControl up::)

+

Limitations: 1) "Up" does not work with controller buttons; and 2) An "Up" hotkey without a normal/down counterpart hotkey will completely take over that key to prevent it from getting stuck down. One way to prevent this is to add a tilde prefix (e.g. ~LControl up::)

"Up" hotkeys and their key-down counterparts (if any) always use the keyboard hook.

On a related note, a technique similar to the above is to make a hotkey into a prefix key. The advantage is that although the hotkey will fire upon release, it will do so only if you did not press any other key while it was held down. For example:

LControl & F1::return  ; Make left-control a prefix by using it in front of "&" at least once.
 LControl::MsgBox You released LControl without having used it to modify any other key.
-

Note: See the Key List for a complete list of keyboard keys and mouse/joystick buttons.

+

Note: See the Key List for a complete list of keyboard keys and mouse/controller buttons.

Multiple hotkeys can be stacked vertically to have them perform the same action. For example:

^Numpad0::
 ^Numpad1::
@@ -158,7 +158,7 @@ 

Context-sensitive Hotkeys

Custom Combinations

Normally shortcut key combinations consist of optional prefix/modifier keys (Ctrl, Alt, Shift and LWin/RWin) and a single suffix key. The standard modifier keys are designed to be used in this manner, so normally have no immediate effect when pressed down.

-

A custom combination of two keys (including mouse but not joystick buttons) can be defined by using " & " between them. Because they are intended for use with prefix keys that are not normally used as such, custom combinations have the following special behavior:

+

A custom combination of two keys (including mouse but not controller buttons) can be defined by using " & " between them. Because they are intended for use with prefix keys that are not normally used as such, custom combinations have the following special behavior:

The Suspend command can temporarily disable all hotkeys except for ones you make exempt. For greater selectivity, use #IfWinActive/Exist.

By means of the Hotkey command, hotkeys can be created dynamically while the script is running. The Hotkey command can also modify, disable, or enable the script's existing hotkeys individually.

-

Joystick hotkeys do not currently support modifier prefixes such as ^ (Ctrl) and # (Win). However, you can use GetKeyState to mimic this effect as shown in the following example:

+

Controller hotkeys do not currently support modifier prefixes such as ^ (Ctrl) and # (Win). However, you can use GetKeyState to mimic this effect as shown in the following example:

Joy2::
 if not GetKeyState("Control")  ; Neither the left nor right Control key is down.
     return  ; i.e. Do nothing.
-MsgBox You pressed the first joystick's second button while holding down the Control key.
+MsgBox You pressed the first controller's second button while holding down the Control key.
 return

There may be times when a hotkey should wait for its own modifier keys to be released before continuing. Consider the following example:

^!s::Send {Delete}
diff --git a/docs/KeyList.htm b/docs/KeyList.htm index 139cdbb85..44d84732d 100644 --- a/docs/KeyList.htm +++ b/docs/KeyList.htm @@ -1,16 +1,16 @@ -List of Keys (Keyboard, Mouse and Joystick) | AutoHotkey - - +List of Keys (Keyboard, Mouse and Controller) | AutoHotkey + + -

List of Keys (Keyboard, Mouse and Joystick)

+

List of Keys (Keyboard, Mouse and Controller)

Table of Contents

-
  • Joystick
  • +
  • Game Controller (Gamepad, Joystick, etc.)
  • Hand-held Remote Controls
  • Special Keys
  • CapsLock and IME
  • @@ -444,25 +444,28 @@

    Other Keys

    -

    Joystick

    -

    Joy1 through Joy32: The buttons of the joystick. To help determine the button numbers for your joystick, use this test script. Note that hotkey prefix symbols such as ^ (control) and + (shift) are not supported (though GetKeyState() can be used as a substitute). Also note that the pressing of joystick buttons always "passes through" to the active window if that window is designed to detect the pressing of joystick buttons.

    -

    Although the following Joystick control names cannot be used as hotkeys, they can be used with GetKeyState():

    + +

    Game Controller (Gamepad, Joystick, etc.)

    +

    Note: For historical reasons, the following button and control names begin with Joy, which stands for joystick. However, they usually also work for other game controllers such as gamepads or steering wheels.

    +

    Joy1 through Joy32: The buttons of the controller. To help determine the button numbers for your controller, use this test script. Note that hotkey prefix symbols such as ^ (control) and + (shift) are not supported (though GetKeyState() can be used as a substitute). Also note that the pressing of controller buttons always "passes through" to the active window if that window is designed to detect the pressing of controller buttons.

    +

    Although the following control names cannot be used as hotkeys, they can be used with GetKeyState():

    -

    Multiple Joysticks: If the computer has more than one joystick and you want to use one beyond the first, include the joystick number (max 16) in front of the control name. For example, 2joy1 is the second joystick's first button.

    -

    Note: If you have trouble getting a script to recognize your joystick, one person reported needing to specify a joystick number other than 1 even though only a single joystick was present. It is unclear how this situation arises or whether it is normal, but experimenting with the joystick number in the joystick test script can help determine if this applies to your system.

    +

    For example, when using Xbox Wireless/360 controllers, JoyX/JoyY is the left stick, JoyR/JoyU the right stick, JoyZ the left and right triggers, and JoyPOV the directional pad (D-pad).

    +

    Multiple controllers: If the computer has more than one controller and you want to use one beyond the first, include the controller number (max 16) in front of the control name. For example, 2joy1 is the second controller's first button.

    +

    Note: If you have trouble getting a script to recognize your controller, specify a controller number other than 1 even though only a single controller is present. It is unclear how this situation arises or whether it is normal, but experimenting with the controller number in the controller test script can help determine if this applies to your system.

    See Also:

    Hand-held Remote Controls

    diff --git a/docs/Tutorial.htm b/docs/Tutorial.htm index c800481bd..07f494a46 100644 --- a/docs/Tutorial.htm +++ b/docs/Tutorial.htm @@ -200,8 +200,8 @@

    a. Keys and their mysterious symbols

    (For the full list of symbols, see the Hotkey page)

    -

    Additionally, for a list of all/most hotkey names that can be used on the left side of a hotkey's double-colon, see List of Keys, Mouse Buttons, and Joystick Controls.

    -

    You can define a custom combination of two (and only two) keys (except joystick buttons) by using & between them. In the example below, you would hold down Numpad0 then press Numpad1 or Numpad2 to trigger one of the hotkeys:

    +

    Additionally, for a list of all/most hotkey names that can be used on the left side of a hotkey's double-colon, see List of Keys, Mouse Buttons, and Controller Controls.

    +

    You can define a custom combination of two (and only two) keys (except controller buttons) by using & between them. In the example below, you would hold down Numpad0 then press Numpad1 or Numpad2 to trigger one of the hotkeys:

    Numpad0 & Numpad1::
     MsgBox, You pressed Numpad1 while holding down Numpad0.
    diff --git a/docs/index.htm b/docs/index.htm
    index 0e7b233a6..94ddbe2f7 100644
    --- a/docs/index.htm
    +++ b/docs/index.htm
    @@ -38,10 +38,10 @@ 

    Quick Reference

    Keyboard and mouse:

    Other:

    For example, Limit1 would prevent unmodified hotkeys such as letters and numbers from being entered, and Limit15 would require at least two modifier keys. If the user types a forbidden modifier combination, the Ctrl+Alt combination is automatically and visibly substituted.

    -

    The Hotkey control has limited capabilities. For example, it does not support mouse/joystick hotkeys or Win (LWin and RWin). One way to work around this is to provide one or more checkboxes as a means for the user to enable extra modifiers such as Win.

    +

    The Hotkey control has limited capabilities. For example, it does not support mouse/controller hotkeys or Win (LWin and RWin). One way to work around this is to provide one or more checkboxes as a means for the user to enable extra modifiers such as Win.

    DateTime

    Description: A box that looks like a single-line edit control but instead accepts a date and/or time. A drop-down calendar is also provided.

    diff --git a/docs/lib/Hotkey.htm b/docs/lib/Hotkey.htm index dd59800b9..0f435fbae 100644 --- a/docs/lib/Hotkey.htm +++ b/docs/lib/Hotkey.htm @@ -151,7 +151,7 @@

    Remarks About Hotkey, If

    Using "Hotkey If" puts context sensitivity into effect for all subsequently created or modified hotkeys. In addition, each If sub-command is mutually exclusive; that is, only the most recent one will be in effect.

    To turn off context sensitivity (that is, to make subsequently-created hotkeys work in all windows), specify any If sub-command but omit the parameters. For example: Hotkey, If or Hotkey, IfWinActive.

    If "Hotkey If" is never used by a script, the bottommost use of any #If or #IfWin directive (if any) will be in effect for the Hotkey command.

    -

    When a mouse or keyboard hotkey is disabled via an If sub-command or directive, it performs its native function; that is, it passes through to the active window as though there is no such hotkey. However, joystick hotkeys always pass through, whether they are disabled or not.

    +

    When a mouse or keyboard hotkey is disabled via an If sub-command or directive, it performs its native function; that is, it passes through to the active window as though there is no such hotkey. However, controller hotkeys always pass through, whether they are disabled or not.

    Variant (Duplicate) Hotkeys

    A particular hotkey can be created more than once if each definition has different IfWin criteria. These are known as hotkey variants. For example:

    diff --git a/docs/lib/KeyWait.htm b/docs/lib/KeyWait.htm index ccb9b4e64..8b495040a 100644 --- a/docs/lib/KeyWait.htm +++ b/docs/lib/KeyWait.htm @@ -2,7 +2,7 @@ KeyWait - Syntax & Usage | AutoHotkey - + @@ -12,21 +12,21 @@

    KeyWait

    -

    Waits for a key or mouse/joystick button to be released or pressed down.

    +

    Waits for a key or mouse/controller button to be released or pressed down.

    KeyWait, KeyName , Options

    Parameters

    KeyName
    -

    This can be just about any single character from the keyboard or one of the key names from the key list, such as a mouse/joystick button. Joystick attributes other than buttons are not supported.

    +

    This can be just about any single character from the keyboard or one of the key names from the key list, such as a mouse/controller button. Controller attributes other than buttons are not supported.

    An explicit virtual key code such as vkFF may also be specified. This is useful in the rare case where a key has no name and produces no visible character when pressed. Its virtual key code can be determined by following the steps at the bottom of the key list page.

    Options
    -

    If this parameter is blank, the command will wait indefinitely for the specified key or mouse/joystick button to be physically released by the user. However, if the keyboard hook is not installed and KeyName is a keyboard key released artificially by means such as the Send command, the key will be seen as having been physically released. The same is true for mouse buttons when the mouse hook is not installed.

    +

    If this parameter is blank, the command will wait indefinitely for the specified key or mouse/controller button to be physically released by the user. However, if the keyboard hook is not installed and KeyName is a keyboard key released artificially by means such as the Send command, the key will be seen as having been physically released. The same is true for mouse buttons when the mouse hook is not installed.

    Options: A string of one or more of the following letters (in any order, with optional spaces in between):

    D: Wait for the key to be pushed down.

    -

    L: Check the logical state of the key, which is the state that the OS and the active window believe the key to be in (not necessarily the same as the physical state). This option is ignored for joystick buttons.

    +

    L: Check the logical state of the key, which is the state that the OS and the active window believe the key to be in (not necessarily the same as the physical state). This option is ignored for controller buttons.

    T: Timeout (e.g. T3). The number of seconds to wait before timing out and setting ErrorLevel to 1. If the key or button achieves the specified state, the command will not wait for the timeout to expire. Instead, it will immediately set ErrorLevel to 0 and the script will continue executing.

    The timeout value can be a floating point number such as 2.5, but it should not be a hexadecimal value such as 0x03.

    @@ -55,7 +55,7 @@

    Examples

    -

    Waits up to 3 seconds for the first joystick button to be pressed down.

    +

    Waits up to 3 seconds for the first controller button to be pressed down.

    KeyWait, Joy1, D T3
    diff --git a/docs/lib/ListHotkeys.htm b/docs/lib/ListHotkeys.htm index 5f5cadf55..04e05c9d2 100644 --- a/docs/lib/ListHotkeys.htm +++ b/docs/lib/ListHotkeys.htm @@ -26,7 +26,7 @@

    ListHotkeys

  • k-hook: The hotkey is implemented via the keyboard hook.
  • m-hook: The hotkey is implemented via the mouse hook.
  • 2-hooks: The hotkey requires both the hooks mentioned above.
  • -
  • joypoll: The hotkey is implemented by polling the joystick at regular intervals.
  • +
  • joypoll: The hotkey is implemented by polling the controller at regular intervals.
  • diff --git a/docs/lib/_If.htm b/docs/lib/_If.htm index bc29948c1..152cfd9b0 100644 --- a/docs/lib/_If.htm +++ b/docs/lib/_If.htm @@ -35,7 +35,7 @@

    Basic Operation

    Like other directives, #If cannot be executed conditionally.

    General Remarks

    -

    When the key, mouse or joystick button combination which forms a hotkey is pressed, the #If expression is evaluated to determine if the hotkey should activate.

    +

    When the key, mouse or controller button combination which forms a hotkey is pressed, the #If expression is evaluated to determine if the hotkey should activate.

    Note: Scripts should not assume that the expression is only evaluated when the key is pressed (see below).

    The expression may also be evaluated whenever the program needs to know whether the hotkey is active. For example, the #If expression for a custom combination like a & b:: might be evaluated when the prefix key (a in this example) is pressed, to determine whether it should act as a custom modifier key.

    Note: Use of #If in an unresponsive script may cause input lag or break hotkeys (see below).

    diff --git a/docs/lib/_IfWinActive.htm b/docs/lib/_IfWinActive.htm index 90e184d88..44e50c214 100644 --- a/docs/lib/_IfWinActive.htm +++ b/docs/lib/_IfWinActive.htm @@ -47,7 +47,7 @@

    Basic Operation

    To turn off context sensitivity, specify any #IfWin directive but omit all of its parameters. For example:

    #IfWinActive

    When #IfWin is turned off (or never used in a script), all hotkeys and hotstrings are enabled for all windows (unless disabled via Suspend or the Hotkey command).

    -

    When a mouse or keyboard hotkey is disabled via #IfWin, it performs its native function; that is, it passes through to the active window as though there is no such hotkey. There is one exception: Joystick hotkeys: although #IfWin works, it never prevents other programs from seeing the press of a button.

    +

    When a mouse or keyboard hotkey is disabled via #IfWin, it performs its native function; that is, it passes through to the active window as though there is no such hotkey. There is one exception: Controller hotkeys: although #IfWin works, it never prevents other programs from seeing the press of a button.

    #IfWin can also be used to alter the behavior of an ordinary key like Enter or Space. This is useful when a particular window ignores that key or performs some action you find undesirable. For example:

    #IfWinActive Reminders ahk_class #32770  ; The "reminders" window in Outlook.
     Enter::Send !o  ; Have an "Enter" keystroke open the selected reminder rather than snoozing it.
    diff --git a/docs/lib/index.htm b/docs/lib/index.htm
    index bcb12eb57..03d9f3af4 100644
    --- a/docs/lib/index.htm
    +++ b/docs/lib/index.htm
    @@ -416,11 +416,11 @@ 

    Alphabetical Command and Function Index

    GetKeyState - Checks if a keyboard key or mouse/joystick button is down or up. Also retrieves joystick status. + Checks if a keyboard key or mouse/controller button is down or up. Also retrieves controller status. GetKeyState() - Checks if a keyboard key or mouse/joystick button is down or up. Also retrieves joystick status. + Checks if a keyboard key or mouse/controller button is down or up. Also retrieves controller status. Gosub @@ -582,7 +582,7 @@

    Alphabetical Command and Function Index

    KeyWait - Waits for a key or mouse/joystick button to be released or pressed down. + Waits for a key or mouse/controller button to be released or pressed down. ListHotkeys diff --git a/docs/misc/Remap.htm b/docs/misc/Remap.htm index 5d9655d61..f0d4d9146 100644 --- a/docs/misc/Remap.htm +++ b/docs/misc/Remap.htm @@ -1,9 +1,9 @@ -Remapping Keys (Keyboard, Mouse and Joystick) | AutoHotkey - - +Remapping Keys (Keyboard, Mouse and Controller) | AutoHotkey + + @@ -11,7 +11,7 @@ -

    Remapping Keys (Keyboard, Mouse and Joystick)

    +

    Remapping Keys (Keyboard, Mouse and Controller)

    Table of Contents

      @@ -187,7 +187,7 @@

      Remapping via the Registry's "Scancode Map"

    • Registry remapping is relatively permanent: a reboot is required to undo the changes or put new ones into effect.
    • Its effect is global: it cannot create remappings specific to a particular user, application, or locale.
    • It cannot send keystrokes that are modified by Shift, Ctrl, Alt, or AltGr. For example, it cannot remap a lowercase character to an uppercase one.
    • -
    • It supports only the keyboard (AutoHotkey has mouse remapping and some limited joystick remapping).
    • +
    • It supports only the keyboard (AutoHotkey has mouse remapping and some limited controller remapping).

    How to Apply Changes to the Registry: There are at least two methods to remap keys via the registry:

      @@ -196,9 +196,9 @@

      Remapping via the Registry's "Scancode Map"

    diff --git a/docs/misc/RemapJoystick.htm b/docs/misc/RemapController.htm similarity index 58% rename from docs/misc/RemapJoystick.htm rename to docs/misc/RemapController.htm index 5b3f69c8d..bc6e15936 100644 --- a/docs/misc/RemapJoystick.htm +++ b/docs/misc/RemapController.htm @@ -1,9 +1,9 @@ -Remapping a Joystick to Keyboard or Mouse | AutoHotkey - - +Remapping a Controller to Keyboard or Mouse | AutoHotkey + + @@ -11,22 +11,22 @@ -

    Remapping a Joystick to Keyboard or Mouse

    +

    Remapping a Controller to Keyboard or Mouse

    Table of Contents

    -

    See the Key List for the complete list of keys and mouse/joystick buttons.

    +

    See the Key List for the complete list of keys and mouse/controller buttons.

    Method #2

    -

    This method is necessary in cases where a key or mouse button must be held down for the entire time that you're holding down a joystick button. The following example makes the joystick's second button become the left-arrow key:

    +

    This method is necessary in cases where a key or mouse button must be held down for the entire time that you're holding down a controller button. The following example makes the controller's second button become the left-arrow key:

    Joy2::
     Send {Left down}  ; Hold down the left-arrow key.
    -KeyWait Joy2  ; Wait for the user to release the joystick button.
    +KeyWait Joy2  ; Wait for the user to release the controller button.
     Send {Left up}  ; Release the left-arrow key.
     return

    Method #3

    -

    This method is necessary in cases where you have more than one joystick hotkey of the type described in Method #2, and you sometimes press and release such hotkeys simultaneously. The following example makes the joystick's third button become the left mouse button:

    +

    This method is necessary in cases where you have more than one controller hotkey of the type described in Method #2, and you sometimes press and release such hotkeys simultaneously. The following example makes the controller's third button become the left mouse button:

    Joy3::
     Send {LButton down}   ; Hold down the left mouse button.
     SetTimer, WaitForButtonUp3, 10
    @@ -83,8 +85,9 @@ 

    Method #3

    return
    -

    Auto-repeating a Keystroke

    -

    Some programs or games might require a key to be sent repeatedly (as though you are holding it down on the keyboard). The following example achieves this by sending spacebar keystrokes repeatedly while you hold down the joystick's second button:

    + +

    Auto-repeating a Keystroke

    +

    Some programs or games might require a key to be sent repeatedly (as though you are holding it down on the keyboard). The following example achieves this by sending spacebar keystrokes repeatedly while you hold down the controller's second button:

    Joy2::
     Send {Space down}   ; Press the spacebar down.
     SetTimer, WaitForJoy2, 30  ; Reduce the number 30 to 20 or 10 to send keys faster. Increase it to send slower.
    @@ -101,17 +104,20 @@ 

    Auto-repeating a Keystroke

    Send {Space down} ; Send another Spacebar keystroke. return
    -

    Context-sensitive Joystick Buttons

    -

    The directives #IfWinActive/Exist can be used to make selected joystick buttons perform a different action (or none at all) depending on the type of window that is active or exists.

    + +

    Context-sensitive Controller Buttons

    +

    The directives #IfWinActive/Exist can be used to make selected controller buttons perform a different action (or none at all) depending on the type of window that is active or exists.

    -

    Using a Joystick as a Mouse

    -

    The Joystick-To-Mouse script converts a joystick into a mouse by remapping its buttons and axis control.

    + +

    Using a Controller as a Mouse

    +

    The Controller-To-Mouse script converts a controller into a mouse by remapping its buttons and axis control.

    -

    Making Other Joystick Controls Send Keystrokes or Mouse Clicks

    -

    To have a script respond to movement of a joystick's axis or POV hat, use SetTimer and GetKeyState().

    +

    Making Other Controller Controls Send Keystrokes or Mouse Clicks

    +

    To have a script respond to movement of a controller's axis or POV hat, use SetTimer and GetKeyState().

    -

    Joystick Axes

    -

    The following example makes the joystick's X and Y axes behave like the arrow key cluster on a keyboard (left, right, up, and down):

    + +

    Controller Axes

    +

    The following example makes the controller's X and Y axes behave like the arrow key cluster on a keyboard (left, right, up, and down):

    #Persistent  ; Keep this script running until the user explicitly exits it.
     SetTimer, WatchAxis, 5
     return
    @@ -143,8 +149,9 @@ 

    Joystick Axes

    Send, {%KeyToHoldDown% down} ; Press it down. return
    -

    Joystick POV Hat

    -

    The following example makes the joystick's POV hat behave like the arrow key cluster on a keyboard; that is, the POV hat will send arrow keystrokes (left, right, up, and down):

    + +

    Controller POV Hat

    +

    The following example makes the controller's POV hat behave like the arrow key cluster on a keyboard; that is, the POV hat will send arrow keystrokes (left, right, up, and down):

    #Persistent  ; Keep this script running until the user explicitly exits it.
     SetTimer, WatchPOV, 5
     return
    @@ -153,7 +160,7 @@ 

    Joystick POV Hat

    POV := GetKeyState("JoyPOV") ; Get position of the POV control. KeyToHoldDownPrev := KeyToHoldDown ; Prev now holds the key that was down before (if any). -; Some joysticks might have a smooth/continous POV rather than one in fixed increments. +; Some controllers might have a smooth/continous POV rather than one in fixed increments. ; To support them all, use a range: if (POV < 0) ; No angle to report KeyToHoldDown := "" @@ -189,12 +196,12 @@

    Auto-repeating a Keystroke

    return }

    Remarks

    -

    A joystick other than first may be used by preceding the button or axis name with the number of the joystick. For example, 2Joy1 would be the second joystick's first button.

    -

    To find other useful joystick scripts, visit the AutoHotkey forum. A keyword search such as Joystick and GetKeyState and Send is likely to produce topics of interest.

    +

    A controller other than first may be used by preceding the button or axis name with the number of the controller. For example, 2Joy1 would be the second controller's first button.

    +

    To find other useful controller scripts, visit the AutoHotkey forum. A keyword search such as Controller and GetKeyState and Send is likely to produce topics of interest.

    diff --git a/docs/scripts/JoystickMouse.ahk b/docs/scripts/ControllerMouse.ahk similarity index 53% rename from docs/scripts/JoystickMouse.ahk rename to docs/scripts/ControllerMouse.ahk index 6a554fd0d..1971770f3 100644 --- a/docs/scripts/JoystickMouse.ahk +++ b/docs/scripts/ControllerMouse.ahk @@ -1,69 +1,74 @@ -; Using a Joystick as a Mouse +; Using a Controller as a Mouse ; https://www.autohotkey.com -; This script converts a joystick into a three-button mouse. It allows each -; button to drag just like a mouse button and it uses virtually no CPU time. -; Also, it will move the cursor faster depending on how far you push the joystick -; from center. You can personalize various settings at the top of the script. +; This script converts a controller (gamepad, joystick, etc.) into a three-button +; mouse. It allows each button to drag just like a mouse button and it uses +; virtually no CPU time. Also, it will move the cursor faster depending on how far +; you push the controller from center. You can personalize various settings at the +; top of the script. +; +; Note: For Xbox controller 2013 and newer (anything newer than the Xbox 360 +; controller), this script will only work if a window it owns is active, +; such as a message box, GUI, or the script's main window. ; Increase the following value to make the mouse cursor move faster: -JoyMultiplier = 0.30 +ContMultiplier = 0.30 -; Decrease the following value to require less joystick displacement-from-center -; to start moving the mouse. However, you may need to calibrate your joystick +; Decrease the following value to require less controller displacement-from-center +; to start moving the mouse. However, you may need to calibrate your controller ; -- ensuring it's properly centered -- to avoid cursor drift. A perfectly tight -; and centered joystick could use a value of 1: -JoyThreshold = 3 +; and centered controller could use a value of 1: +ContThreshold = 3 ; Change the following to true to invert the Y-axis, which causes the mouse to ; move vertically in the direction opposite the stick: InvertYAxis := false -; Change these values to use joystick button numbers other than 1, 2, and 3 for +; Change these values to use controller button numbers other than 1, 2, and 3 for ; the left, right, and middle mouse buttons. Available numbers are 1 through 32. -; Use the Joystick Test Script to find out your joystick's numbers more easily. +; Use the Controller Test Script to find out your controller's numbers more easily. ButtonLeft = 1 ButtonRight = 2 ButtonMiddle = 3 -; If your joystick has a POV control, you can use it as a mouse wheel. The +; If your controller has a POV control, you can use it as a mouse wheel. The ; following value is the number of milliseconds between turns of the wheel. ; Decrease it to have the wheel turn faster: WheelDelay = 250 -; If your system has more than one joystick, increase this value to use a joystick -; other than the first: -JoystickNumber = 1 +; If your system has more than one controller, increase this value to use a +; controller other than the first: +ControllerNumber = 1 ; END OF CONFIG SECTION -- Don't change anything below this point unless you want ; to alter the basic nature of the script. #SingleInstance -JoystickPrefix = %JoystickNumber%Joy -Hotkey, %JoystickPrefix%%ButtonLeft%, ButtonLeft -Hotkey, %JoystickPrefix%%ButtonRight%, ButtonRight -Hotkey, %JoystickPrefix%%ButtonMiddle%, ButtonMiddle +ControllerPrefix = %ControllerNumber%Joy +Hotkey, %ControllerPrefix%%ButtonLeft%, ButtonLeft +Hotkey, %ControllerPrefix%%ButtonRight%, ButtonRight +Hotkey, %ControllerPrefix%%ButtonMiddle%, ButtonMiddle ; Calculate the axis displacements that are needed to start moving the cursor: -JoyThresholdUpper := 50 + JoyThreshold -JoyThresholdLower := 50 - JoyThreshold +ContThresholdUpper := 50 + ContThreshold +ContThresholdLower := 50 - ContThreshold if InvertYAxis YAxisMultiplier = -1 else YAxisMultiplier = 1 -SetTimer, WatchJoystick, 10 ; Monitor the movement of the joystick. +SetTimer, WatchController, 10 ; Monitor the movement of the controller. -GetKeyState, JoyInfo, %JoystickNumber%JoyInfo -IfInString, JoyInfo, P ; Joystick has POV control, so use it as a mouse wheel. +GetKeyState, JoyInfo, %ControllerNumber%JoyInfo +IfInString, JoyInfo, P ; Controller has POV control, so use it as a mouse wheel. SetTimer, MouseWheel, %WheelDelay% return ; End of auto-execute section. ; The subroutines below do not use KeyWait because that would sometimes trap the -; WatchJoystick quasi-thread beneath the wait-for-button-up thread, which would -; effectively prevent mouse-dragging with the joystick. +; WatchController quasi-thread beneath the wait-for-button-up thread, which would +; effectively prevent mouse-dragging with the controller. ButtonLeft: SetMouseDelay, -1 ; Makes movement smoother. @@ -84,7 +89,7 @@ SetTimer, WaitForMiddleButtonUp, 10 return WaitForLeftButtonUp: -if GetKeyState(JoystickPrefix . ButtonLeft) +if GetKeyState(ControllerPrefix . ButtonLeft) return ; The button is still, down, so keep waiting. ; Otherwise, the button has been released. SetTimer, WaitForLeftButtonUp, Off @@ -93,7 +98,7 @@ MouseClick, left,,, 1, 0, U ; Release the mouse button. return WaitForRightButtonUp: -if GetKeyState(JoystickPrefix . ButtonRight) +if GetKeyState(ControllerPrefix . ButtonRight) return ; The button is still, down, so keep waiting. ; Otherwise, the button has been released. SetTimer, WaitForRightButtonUp, Off @@ -101,51 +106,51 @@ MouseClick, right,,, 1, 0, U ; Release the mouse button. return WaitForMiddleButtonUp: -if GetKeyState(JoystickPrefix . ButtonMiddle) +if GetKeyState(ControllerPrefix . ButtonMiddle) return ; The button is still, down, so keep waiting. ; Otherwise, the button has been released. SetTimer, WaitForMiddleButtonUp, Off MouseClick, middle,,, 1, 0, U ; Release the mouse button. return -WatchJoystick: +WatchController: MouseNeedsToBeMoved := false ; Set default. SetFormat, float, 03 -GetKeyState, JoyX, %JoystickNumber%JoyX -GetKeyState, JoyY, %JoystickNumber%JoyY -if JoyX > %JoyThresholdUpper% +GetKeyState, JoyX, %ControllerNumber%JoyX +GetKeyState, JoyY, %ControllerNumber%JoyY +if JoyX > %ContThresholdUpper% { MouseNeedsToBeMoved := true - DeltaX := JoyX - JoyThresholdUpper + DeltaX := JoyX - ContThresholdUpper } -else if JoyX < %JoyThresholdLower% +else if JoyX < %ContThresholdLower% { MouseNeedsToBeMoved := true - DeltaX := JoyX - JoyThresholdLower + DeltaX := JoyX - ContThresholdLower } else DeltaX = 0 -if JoyY > %JoyThresholdUpper% +if JoyY > %ContThresholdUpper% { MouseNeedsToBeMoved := true - DeltaY := JoyY - JoyThresholdUpper + DeltaY := JoyY - ContThresholdUpper } -else if JoyY < %JoyThresholdLower% +else if JoyY < %ContThresholdLower% { MouseNeedsToBeMoved := true - DeltaY := JoyY - JoyThresholdLower + DeltaY := JoyY - ContThresholdLower } else DeltaY = 0 if MouseNeedsToBeMoved { SetMouseDelay, -1 ; Makes movement smoother. - MouseMove, DeltaX * JoyMultiplier, DeltaY * JoyMultiplier * YAxisMultiplier, 0, R + MouseMove, DeltaX * ContMultiplier, DeltaY * ContMultiplier * YAxisMultiplier, 0, R } return MouseWheel: -GetKeyState, JoyPOV, %JoystickNumber%JoyPOV +GetKeyState, JoyPOV, %ControllerNumber%JoyPOV if JoyPOV = -1 ; No angle. return if (JoyPOV > 31500 or JoyPOV < 4500) ; Forward diff --git a/docs/scripts/ControllerTest.ahk b/docs/scripts/ControllerTest.ahk new file mode 100644 index 000000000..a8abc753e --- /dev/null +++ b/docs/scripts/ControllerTest.ahk @@ -0,0 +1,98 @@ +; Controller Test Script +; https://www.autohotkey.com +; This script helps determine the button numbers and other attributes +; of your controller (gamepad, joystick, etc.). It might also reveal +; if your controller is in need of calibration; that is, whether the +; range of motion of each of its axes is from 0 to 100 percent as it +; should be. If calibration is needed, use the operating system's +; control panel or the software that came with your controller. + +; May 24, 2023: Replaced ToolTip and MsgBox with GUI. +; April 14, 2023: Renamed 'joystick' to 'controller'. +; July 6, 2005: Added auto-detection of joystick number. +; May 8, 2005 : Fixed: JoyAxes is no longer queried as a means of +; detecting whether the joystick is connected. Some joysticks are +; gamepads and don't have even a single axis. + +; If you want to unconditionally use a specific controller number, change +; the following value from 0 to the number of the controller (1-16). +; A value of 0 causes the controller number to be auto-detected: +ControllerNumber = 0 + +; END OF CONFIG SECTION. Do not make changes below this point unless +; you wish to alter the basic functionality of the script. + +Gui, +AlwaysOnTop +Gui, Add, Text, w300, Note: For Xbox controller 2013 and newer (anything newer than the Xbox 360 controller), this script can only detect controller events if a window it owns is active (like this one). +Gui, Add, Edit, w300 h300 +ReadOnly +Gui, Show,, Controller Test Script + +; Auto-detect the controller number if called for: +if ControllerNumber <= 0 +{ + Loop 16 ; Query each controller number to find out which ones exist. + { + GetKeyState, ContName, %A_Index%JoyName + if ContName <> + { + ControllerNumber = %A_Index% + break + } + } + if ControllerNumber <= 0 + { + GuiControl,, Edit1, The system does not appear to have any controllers. + return + } +} + +#SingleInstance +SetFormat, float, 03 ; Omit decimal point from axis position percentages. +GetKeyState, cont_buttons, %ControllerNumber%JoyButtons +GetKeyState, cont_name, %ControllerNumber%JoyName +GetKeyState, cont_info, %ControllerNumber%JoyInfo +Loop +{ + buttons_down = + Loop, %cont_buttons% + { + GetKeyState, Cont%A_Index%, %ControllerNumber%Joy%A_Index% + if Cont%A_Index% = D + buttons_down = %buttons_down%%A_Space%%A_Index% + } + GetKeyState, ContX, %ControllerNumber%JoyX + axis_info = X%ContX% + GetKeyState, ContY, %ControllerNumber%JoyY + axis_info = %axis_info%%A_Space%%A_Space%Y%ContY% + IfInString, cont_info, Z + { + GetKeyState, ContZ, %ControllerNumber%JoyZ + axis_info = %axis_info%%A_Space%%A_Space%Z%ContZ% + } + IfInString, cont_info, R + { + GetKeyState, ContR, %ControllerNumber%JoyR + axis_info = %axis_info%%A_Space%%A_Space%R%ContR% + } + IfInString, cont_info, U + { + GetKeyState, ContU, %ControllerNumber%JoyU + axis_info = %axis_info%%A_Space%%A_Space%U%ContU% + } + IfInString, cont_info, V + { + GetKeyState, ContV, %ControllerNumber%JoyV + axis_info = %axis_info%%A_Space%%A_Space%V%ContV% + } + IfInString, cont_info, P + { + GetKeyState, ContPOV, %ControllerNumber%JoyPOV + axis_info = %axis_info%%A_Space%%A_Space%POV%ContPOV% + } + GuiControl,, Edit1, %cont_name% (#%ControllerNumber%):`n%axis_info%`nButtons Down: %buttons_down% + Sleep, 100 +} +return + +GuiClose: +ExitApp diff --git a/docs/scripts/JoystickTest.ahk b/docs/scripts/JoystickTest.ahk deleted file mode 100644 index ee9124b4a..000000000 --- a/docs/scripts/JoystickTest.ahk +++ /dev/null @@ -1,88 +0,0 @@ -; Joystick Test Script -; https://www.autohotkey.com -; This script helps determine the button numbers and other attributes -; of your joystick. It might also reveal if your joystick is in need -; of calibration; that is, whether the range of motion of each of its -; axes is from 0 to 100 percent as it should be. If calibration is -; needed, use the operating system's control panel or the software -; that came with your joystick. - -; July 6, 2005: Added auto-detection of joystick number. -; May 8, 2005 : Fixed: JoyAxes is no longer queried as a means of -; detecting whether the joystick is connected. Some joysticks are -; gamepads and don't have even a single axis. - -; If you want to unconditionally use a specific joystick number, change -; the following value from 0 to the number of the joystick (1-16). -; A value of 0 causes the joystick number to be auto-detected: -JoystickNumber = 0 - -; END OF CONFIG SECTION. Do not make changes below this point unless -; you wish to alter the basic functionality of the script. - -; Auto-detect the joystick number if called for: -if JoystickNumber <= 0 -{ - Loop 16 ; Query each joystick number to find out which ones exist. - { - GetKeyState, JoyName, %A_Index%JoyName - if JoyName <> - { - JoystickNumber = %A_Index% - break - } - } - if JoystickNumber <= 0 - { - MsgBox The system does not appear to have any joysticks. - ExitApp - } -} - -#SingleInstance -SetFormat, float, 03 ; Omit decimal point from axis position percentages. -GetKeyState, joy_buttons, %JoystickNumber%JoyButtons -GetKeyState, joy_name, %JoystickNumber%JoyName -GetKeyState, joy_info, %JoystickNumber%JoyInfo -Loop -{ - buttons_down = - Loop, %joy_buttons% - { - GetKeyState, joy%A_Index%, %JoystickNumber%joy%A_Index% - if joy%A_Index% = D - buttons_down = %buttons_down%%A_Space%%A_Index% - } - GetKeyState, JoyX, %JoystickNumber%JoyX - axis_info = X%JoyX% - GetKeyState, JoyY, %JoystickNumber%JoyY - axis_info = %axis_info%%A_Space%%A_Space%Y%JoyY% - IfInString, joy_info, Z - { - GetKeyState, JoyZ, %JoystickNumber%JoyZ - axis_info = %axis_info%%A_Space%%A_Space%Z%JoyZ% - } - IfInString, joy_info, R - { - GetKeyState, JoyR, %JoystickNumber%JoyR - axis_info = %axis_info%%A_Space%%A_Space%R%JoyR% - } - IfInString, joy_info, U - { - GetKeyState, JoyU, %JoystickNumber%JoyU - axis_info = %axis_info%%A_Space%%A_Space%U%JoyU% - } - IfInString, joy_info, V - { - GetKeyState, JoyV, %JoystickNumber%JoyV - axis_info = %axis_info%%A_Space%%A_Space%V%JoyV% - } - IfInString, joy_info, P - { - GetKeyState, joyp, %JoystickNumber%JoyPOV - axis_info = %axis_info%%A_Space%%A_Space%POV%joyp% - } - ToolTip, %joy_name% (#%JoystickNumber%):`n%axis_info%`nButtons Down: %buttons_down%`n`n(right-click the tray icon to exit) - Sleep, 100 -} -return diff --git a/docs/scripts/index.htm b/docs/scripts/index.htm index 2bfba36dd..d7ab0b2d8 100644 --- a/docs/scripts/index.htm +++ b/docs/scripts/index.htm @@ -25,8 +25,8 @@

    Table of Contents

  • Easy Window Dragging (KDE style)
  • Easy Access to Favorite Folders
  • IntelliSense
  • -
  • Using a Joystick as a Mouse
  • -
  • Joystick Test Script
  • +
  • Using a Controller as a Mouse
  • +
  • Controller Test Script
  • On-Screen ANSI Keyboard (OSAK)
  • Minimize Window to Tray Menu
  • Changing MsgBox's Button Names
  • @@ -86,13 +86,16 @@

    IntelliSense

    This script watches while you edit an AutoHotkey script. When it sees you type a command followed by a comma or space, it displays that command's parameter list to guide you. In addition, you can press Ctrl+F1 (or another hotkey of your choice) to display that command's page in the help file. To dismiss the parameter list, press Esc or Enter.

    Show code

    -

    Using a Joystick as a Mouse

    -

    This script converts a joystick into a three-button mouse. It allows each button to drag just like a mouse button and it uses virtually no CPU time. Also, it will move the cursor faster depending on how far you push the joystick from center. You can personalize various settings at the top of the script.

    -

    Show code

    + +

    Using a Controller as a Mouse

    +

    This script converts a controller (gamepad, joystick, etc.) into a three-button mouse. It allows each button to drag just like a mouse button and it uses virtually no CPU time. Also, it will move the cursor faster depending on how far you push the controller from center. You can personalize various settings at the top of the script.

    +

    Note: For Xbox controller 2013 and newer (anything newer than the Xbox 360 controller), this script will only work if a window it owns is active, such as a message box, GUI, or the script's main window.

    +

    Show code

    -

    Joystick Test Script

    -

    This script helps determine the button numbers and other attributes of your joystick. It might also reveal if your joystick is in need of calibration; that is, whether the range of motion of each of its axes is from 0 to 100 percent as it should be. If calibration is needed, use the operating system's control panel or the software that came with your joystick.

    -

    Show code

    + +

    Controller Test Script

    +

    This script helps determine the button numbers and other attributes of your controller (gamepad, joystick, etc.). It might also reveal if your controller is in need of calibration; that is, whether the range of motion of each of its axes is from 0 to 100 percent as it should be. If calibration is needed, use the operating system's control panel or the software that came with your controller.

    +

    Show code

    On-Screen ANSI Keyboard (OSAK)

    Authors: Jon, Lehnemann, anonymous1184, KeronCyst

    diff --git a/docs/static/source/data_index.js b/docs/static/source/data_index.js index a6e0c7279..a16f35820 100644 --- a/docs/static/source/data_index.js +++ b/docs/static/source/data_index.js @@ -337,7 +337,7 @@ indexData = [ ["built-in functions","Functions.htm#BuiltIn"], ["built-in variables","Variables.htm#BuiltIn"], ["Button controls (GUI)","lib/GuiControls.htm#Button"], - ["button list (mouse and joystick)","KeyList.htm"], + ["button list (mouse and controller)","KeyList.htm"], ["button state","lib/GetKeyState.htm#function"], ["ByRef","Functions.htm#ByRef",4], ["caching (concepts)","Concepts.htm#caching"], @@ -743,10 +743,12 @@ indexData = [ ["IsSet()","lib/IsSet.htm",2], ["IsVariadic property (Func)","lib/Func.htm#IsVariadic",8], ["Join (continuation sections)","Scripts.htm#Join"], - ["Joystick","KeyList.htm#Joystick"], + ["Joystick","KeyList.htm#Controller"], + ["Controller","KeyList.htm#Controller"], + ["Gamepad","KeyList.htm#Controller"], ["JScript, embedded/inline","lib/DllCall.htm#COM"], ["Keep directive (Ahk2Exe)","misc/Ahk2ExeDirectives.htm#IgnoreKeep",99], - ["key list (keyboard, mouse, joystick)","KeyList.htm"], + ["key list (keyboard, mouse, controller)","KeyList.htm"], ["key state","lib/GetKeyState.htm#function"], ["keyboard hook","lib/_InstallKeybdHook.htm"], ["KeyHistory","lib/KeyHistory.htm",6,""], @@ -1008,7 +1010,7 @@ indexData = [ ["regular expressions: SetTitleMatchMode RegEx","lib/SetTitleMatchMode.htm#RegEx"], ["RegWrite","lib/RegWrite.htm",6,"SSSSS"], ["Reload","lib/Reload.htm",6,""], - ["remap joystick","misc/RemapJoystick.htm"], + ["remap controller","misc/RemapController.htm"], ["remap keys or mouse buttons","misc/Remap.htm"], ["remote controls, hand-held","scripts/index.htm#WinLIRC"], ["remove folder/directory","lib/FileRemoveDir.htm"],