Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

Using Keyboard Numpad as a Mouse


  • Please log in to reply
83 replies to this topic
deguix
  • Members
  • 87 posts
  • Last active: Jun 17 2014 05:18 AM
  • Joined: 26 Aug 2004
This has 700+ lines of codes script which makes your numpad into a mouse. This is like the MouseKeys from Windows, however this has some advanced features like:

- Keys for mouse wheel and left, middle, right, X1 and X2 mouse buttons. (X1 and X2 only supportable on Win2000+.)
- Very smooth movements.
- Much faster speed and acceleration.
- Customizable normal, acceleration and maximum speeds for both mouse movements and wheel.
- Adjustable rotation. With this you can even make this mouse to be inversed like on some flight simulators.
- Uses ScrollLock for activation. This enables you to use the normal NumPad when you don't want the script activated.
- Button/wheel keys are usable even with mouse devices that don't have the wheel or middle, X1 or X2 buttons. (This depends if your mouse hardware support the wheel or those buttons.)

Newest version for AHK2 (2.0-a011-177f85e) is found in my last post in this thread. It's the same as the code for AHK1, but only supported on AHK2 alpha.

Newest version (as found at the end of the thread - tested on AHK 1.1.00.00):
;; Using Keyboard NumPad as a Mouse -- by deguix
; http://www.autohotkey.com
; This script makes mousing with your keyboard almost as easy
; as using a real mouse (maybe even easier for some tasks).
; It supports up to five mouse buttons and the turning of the
; mouse wheel.  It also features customizable movement speed,
; acceleration, and "axis inversion".

/*
o------------------------------------------------------------o
|Using Keyboard NumPad as a Mouse                            |
(------------------------------------------------------------)
| By deguix           / A Script file for AutoHotkey 1.0.48+ |
|                    ----------------------------------------|
|                                                            |
|    This script is an example of use of AutoHotkey. It uses |
| the remapping of NumPad keys of a keyboard to transform it |
| into a mouse. Some features are the acceleration which     |
| enables you to increase the mouse movement when holding    |
| a key for a long time, and the rotation which makes the    |
| NumPad mouse to "turn". I.e. NumPadDown as NumPadUp        |
| and vice-versa. See the list of keys used below:           |
|------------------------------------------------------------|
| Keys                  | Description                        |
|------------------------------------------------------------|
| ScrollLock (toggle on)| Activates NumPad mouse mode.       |
|-----------------------|------------------------------------|
| NumPad0               | Left mouse button click.           |
| NumPad5               | Middle mouse button click.         |
| NumPadDot             | Right mouse button click.          |
| NumPadDiv/NumPadMult  | X1/X2 mouse button click. (Win 2k+)|
| NumPadSub/NumPadAdd   | Moves up/down the mouse wheel.     |
| NumPadEnter           | Mouse movement speed modifier key. |
|-----------------------|------------------------------------|
| NumLock (toggled off) | Activates mouse movement mode.     |
|-----------------------|------------------------------------|
| NumPadEnd/Down/PgDn/  | Mouse movement.                    |
| /Left/Right/Home/Up/  |                                    |
| /PgUp                 |                                    |
| NumPadEnter           | Mouse movement speed modifier key. |
|-----------------------|------------------------------------|
| NumLock (toggled on)  | Activates mousewheel movement mode |
|-----------------------|------------------------------------|
| NumPad1-9 (except 5)  | Mouse wheel movement.*             |
| NumPadEnter           | Mouse wheel mov. speed mod. key.** |
|------------------------------------------------------------|
| NumPadEnter (pressed) | Activates mouse speed adj. mode.   |
|-----------------------|------------------------------------|
| NumPadHome/NumPadEnd/ | +/- acceleration (pixels/cycles).  |
| NumPad7/NumPad1       |                                    |
| NumPadUp/NumPadDown   | +/- initial speed (pixels).        |
| NumPad8/NumPad2       |                                    |
| NumPadPgUp/NumPadPgDn | +/- maximum speed (pixels).        |
| NumPad9/NumPad3       |                                    |
| NumPadLeft/NumPadRight| +/- clockwise rotation (45° degree)|
| NumPad4/NumPad6       |                                    |
|------------------------------------------------------------|
| * = Left/Right movements are only supported in Vista+.     |
| ** = These options are affected by the mouse wheel speed   |
| adjusted on Control Panel as well. If you don't have a     |
| mouse with wheel, the default is 3 +/- lines per option    |
| button press.                                              |
o------------------------------------------------------------o
*/

;START OF CONFIG SECTION

#SingleInstance force
#MaxHotkeysPerInterval 500

; Using the keyboard hook to implement the NumPad hotkeys prevents
; them from interfering with the generation of ANSI characters such
; as à.  This is because AutoHotkey generates such characters
; by holding down ALT and sending a series of NumPad keystrokes.
; Hook hotkeys are smart enough to ignore such keystrokes.
#UseHook

MouseSpeed:=5
MouseAccelerationSpeed:=5 ;in pixels/MouseAccelerationCycles
MouseAccelerationCycles:=50 ;interval of timer executions to increase speed by the variable above
MouseAccelerationTimerInterval:=10 ;in milliseconds (this ends up to being approximate depending on computer performance)
MouseMaxSpeed:=10
MouseRotationAngle:=0

;Mouse wheel speed is also set on Control Panel. As that
;will affect the normal mouse behavior, the real speed of
;these three below are times the normal mouse wheel speed.
MouseWheelSpeed:=2
MouseWheelAccelerationSpeed:=1 ;in pixels/MouseAccelerationCycles
MouseWheelAccelerationCycles:=50 ;interval of timer executions to increase speed by the variable above
MouseWheelAccelerationTimerInterval:=35 ;in milliseconds (this ends up to being approximate depending on computer performance)
MouseWheelMaxSpeed:=5
MouseWheelRotationAngle:=0

MouseButtonPressCheckTimerInterval:=10

;0=Pressing a button and releasing = down + up events. 1=First time pressing/releasing = down, second time = up.
MouseButtonClickLockDownState:=0
MouseButtonMovementLockDownState:=0

;END OF CONFIG SECTION

PI:= 4*ATan(1)

;This is needed or key presses would faulty send their natural
;actions. Like NumPadDiv would send sometimes "/" to the
;screen.
#InstallKeybdHook

Temp = 0
Temp2 = 0

MouseRotationAnglePart = %MouseRotationAngle%
;Divide by 45° because MouseMove only supports whole numbers,
;and changing the mouse rotation to a number lesser than 45°
;could make strange movements.
;
;For example: 22.5° when pressing NumPadUp:
;  First it would move upwards until the speed
;  to the side reaches 1.
MouseRotationAnglePart /= 45
MouseWheelRotationAnglePart = %MouseRotationAngle%
MouseWheelRotationAnglePart /= 45

MovementVectorMagnitude:=0
MovementVectorDirection:=0
MovementVectors:=0
MovementVectorDefaultMagnitude:=MouseSpeed

MovementWheelVectorMagnitude:=0
MovementWheelVectorDirection:=0
MovementWheelVectors:=0
MovementWheelVectorDefaultMagnitude:=MouseWheelSpeed

Buttons:=0

SetKeyDelay, -1
SetMouseDelay, -1

Hotkey, *NumPad0, ButtonLeftClick
Hotkey, *NumPadIns, ButtonLeftClickIns
Hotkey, *NumPad5, ButtonMiddleClick
Hotkey, *NumPadClear, ButtonMiddleClickClear
Hotkey, *NumPadDot, ButtonRightClick
Hotkey, *NumPadDel, ButtonRightClickDel
Hotkey, *NumPadDiv, ButtonX1Click
Hotkey, *NumPadMult, ButtonX2Click

Hotkey, *NumPadSub, ButtonWheelUp
Hotkey, *NumPadAdd, ButtonWheelDown

Hotkey, *NumPadRight, ButtonRight
Hotkey, *NumPadPgUp, ButtonUpRight
Hotkey, *NumPadUp, ButtonUp
Hotkey, *NumPadHome, ButtonUpLeft
Hotkey, *NumPadLeft, ButtonLeft
Hotkey, *NumPadEnd, ButtonDownLeft
Hotkey, *NumPadDown, ButtonDown
Hotkey, *NumPadPgDn, ButtonDownRight

Hotkey, *NumPad6, ButtonWheelRight
Hotkey, *NumPad9, ButtonWheelUpRight
Hotkey, *NumPad8, ButtonWheelUp
Hotkey, *NumPad7, ButtonWheelUpLeft
Hotkey, *NumPad4, ButtonWheelLeft
Hotkey, *NumPad1, ButtonWheelDownLeft
Hotkey, *NumPad2, ButtonWheelDown
Hotkey, *NumPad3, ButtonWheelDownRight

Hotkey, NumPadEnter & NumPadUp, ButtonSpeedUp
Hotkey, NumPadEnter & NumPadDown, ButtonSpeedDown
Hotkey, NumPadEnter & NumPadHome, ButtonAccelerationSpeedUp
Hotkey, NumPadEnter & NumPadEnd, ButtonAccelerationSpeedDown
Hotkey, NumPadEnter & NumPadPgUp, ButtonMaxSpeedUp
Hotkey, NumPadEnter & NumPadPgDn, ButtonMaxSpeedDown
Hotkey, NumPadEnter & NumPadLeft, ButtonRotationAngleUp
Hotkey, NumPadEnter & NumPadRight, ButtonRotationAngleDown

Hotkey, NumPadEnter & NumPad8, ButtonWheelSpeedUp
Hotkey, NumPadEnter & NumPad2, ButtonWheelSpeedDown
Hotkey, NumPadEnter & NumPad7, ButtonWheelAccelerationSpeedUp
Hotkey, NumPadEnter & NumPad1, ButtonWheelAccelerationSpeedDown
Hotkey, NumPadEnter & NumPad9, ButtonWheelMaxSpeedUp
Hotkey, NumPadEnter & NumPad3, ButtonWheelMaxSpeedDown
Hotkey, NumPadEnter & NumPad4, ButtonWheelRotationAngleUp
Hotkey, NumPadEnter & NumPad6, ButtonWheelRotationAngleDown

Hotkey, NumPadEnter, ButtonEnter

Gosub, ~ScrollLock  ; Initialize based on current ScrollLock state.
return

;Key activation support

~ScrollLock::
; Wait for it to be released because otherwise the hook state gets reset
; while the key is down, which causes the up-event to get suppressed,
; which in turn prevents toggling of the ScrollLock state/light:
KeyWait, ScrollLock
GetKeyState, ScrollLockState, ScrollLock, T
If ScrollLockState = D
{
  Hotkey, *NumPad0, on
  Hotkey, *NumPadIns, on
  Hotkey, *NumPad5, on
  Hotkey, *NumPadDot, on
  Hotkey, *NumPadDel, on
  Hotkey, *NumPadDiv, on
  Hotkey, *NumPadMult, on

  Hotkey, *NumPadSub, on
  Hotkey, *NumPadAdd, on

  Hotkey, *NumPadUp, on
  Hotkey, *NumPadDown, on
  Hotkey, *NumPadLeft, on
  Hotkey, *NumPadRight, on
  Hotkey, *NumPadHome, on
  Hotkey, *NumPadEnd, on
  Hotkey, *NumPadPgUp, on
  Hotkey, *NumPadPgDn, on

  Hotkey, *NumPad6, on
  Hotkey, *NumPad9, on
  Hotkey, *NumPad8, on
  Hotkey, *NumPad7, on
  Hotkey, *NumPad4, on
  Hotkey, *NumPad1, on
  Hotkey, *NumPad2, on
  Hotkey, *NumPad3, on

  Hotkey, NumPadEnter & NumPadUp, on
  Hotkey, NumPadEnter & NumPadDown, on
  Hotkey, NumPadEnter & NumPadHome, on
  Hotkey, NumPadEnter & NumPadEnd, on
  Hotkey, NumPadEnter & NumPadPgUp, on
  Hotkey, NumPadEnter & NumPadPgDn, on
  Hotkey, NumPadEnter & NumPadLeft, on
  Hotkey, NumPadEnter & NumPadRight, on

  Hotkey, NumPadEnter & NumPad8, on
  Hotkey, NumPadEnter & NumPad2, on
  Hotkey, NumPadEnter & NumPad7, on
  Hotkey, NumPadEnter & NumPad1, on
  Hotkey, NumPadEnter & NumPad9, on
  Hotkey, NumPadEnter & NumPad3, on
 
  Hotkey, NumPadEnter, on
}
else
{
  Hotkey, *NumPad0, off
  Hotkey, *NumPadIns, off
  Hotkey, *NumPad5, off
  Hotkey, *NumPadDot, off
  Hotkey, *NumPadDel, off
  Hotkey, *NumPadDiv, off
  Hotkey, *NumPadMult, off

  Hotkey, *NumPadSub, off
  Hotkey, *NumPadAdd, off

  Hotkey, *NumPadUp, off
  Hotkey, *NumPadDown, off
  Hotkey, *NumPadLeft, off
  Hotkey, *NumPadRight, off
  Hotkey, *NumPadHome, off
  Hotkey, *NumPadEnd, off
  Hotkey, *NumPadPgUp, off
  Hotkey, *NumPadPgDn, off

  Hotkey, *NumPad6, off
  Hotkey, *NumPad9, off
  Hotkey, *NumPad8, off
  Hotkey, *NumPad7, off
  Hotkey, *NumPad4, off
  Hotkey, *NumPad1, off
  Hotkey, *NumPad2, off
  Hotkey, *NumPad3, off

  Hotkey, NumPadEnter & NumPadUp, off
  Hotkey, NumPadEnter & NumPadDown, off
  Hotkey, NumPadEnter & NumPadHome, off
  Hotkey, NumPadEnter & NumPadEnd, off
  Hotkey, NumPadEnter & NumPadPgUp, off
  Hotkey, NumPadEnter & NumPadPgDn, off
  Hotkey, NumPadEnter & NumPadLeft, off
  Hotkey, NumPadEnter & NumPadRight, off

  Hotkey, NumPadEnter & NumPad8, off
  Hotkey, NumPadEnter & NumPad2, off
  Hotkey, NumPadEnter & NumPad7, off
  Hotkey, NumPadEnter & NumPad1, off
  Hotkey, NumPadEnter & NumPad9, off
  Hotkey, NumPadEnter & NumPad3, off
 
  Hotkey, NumPadEnter, off
}
return

ButtonEnter:
Send, {NumPadEnter}
Return

;Mouse click support
ButtonLeftClick:
ButtonLeftClickIns:
ButtonClickType:="Left"
MouseButtonName:="LButton"
Goto ButtonClickStart
ButtonMiddleClick:
ButtonMiddleClickClear:
ButtonClickType:="Middle"
MouseButtonName:="MButton"
Goto ButtonClickStart
ButtonRightClick:
ButtonRightClickDel:
ButtonClickType:="Right"
MouseButtonName:="RButton"
Goto ButtonClickStart
ButtonX1Click:
ButtonClickType:="X1"
MouseButtonName:="XButton1"
Goto ButtonClickStart
ButtonX2Click:
ButtonClickType:="X2"
MouseButtonName:="XButton2"
ButtonClickStart:
StringReplace, ButtonName, A_ThisHotkey, *
If (ButtonDown_%ButtonName%!=1)
{
  ButtonDown_%ButtonName%:=1
  Buttons:=Buttons+1
  Button%Buttons%Name:=ButtonName
  Button%Buttons%ClickType:=ButtonClickType
  Button%Buttons%MouseButtonName:=MouseButtonName
  Button%Buttons%Initialized:=0
  Button%Buttons%UnHoldStep:=0
  If (Buttons = 1)
    SetTimer, MouseButtonPressCheck, % MouseButtonPressCheckTimerInterval
}
Return

MouseButtonPressCheck:
If (Buttons=0)
{
  SetTimer, MouseButtonPressCheck, off
  Return
}

Button:=0
Loop
{
  Button:=Button+1
  If (Button%Buttons%Initialized=0)
  {
    GetKeyState, MouseButtonState, % Button%Button%MouseButtonName
    If (MouseButtonState="D")
      Continue
    MouseClick, % Button%Button%ClickType,,, 1, 0, D
    Button%Buttons%Initialized:=1
  }
 
  GetKeyState, ButtonState, % Button%Button%Name, P
  If (ButtonState="U" and (MouseButtonClickLockDownState=0 or (MouseButtonClickLockDownState=1 and Button%Buttons%UnHoldStep=2)))
  {
    ButtonName:=Button%Buttons%Name
    ButtonDown_%ButtonName%:=0
    MouseClick, % Button%Button%ClickType,,, 1, 0, U
   
    ButtonTemp:=Button
    ButtonTempPrev:=ButtonTemp-1

    Loop
    {
      ButtonTemp:=ButtonTemp+1
      ButtonTempPrev:=ButtonTempPrev+1
     
      If (Buttons<ButtonTemp)
      {
        Button%ButtonTempPrev%Name:=""
        Button%ButtonTempPrev%ClickType:=""
        Button%ButtonTempPrev%MouseButtonName:=""
        Button%ButtonTempPrev%Initialized:=0
        Break
      }
      Button%ButtonTempPrev%Name:=Button%ButtonTemp%Name
      Button%ButtonTempPrev%ClickType:=Button%ButtonTemp%ClickType
      Button%ButtonTempPrev%MouseButtonName:=Button%ButtonTemp%MouseButtonName
      Button%ButtonTempPrev%Initialized:=Button%ButtonTemp%Initialized
    }
    Buttons:=Buttons-1
  }
  
  If(ButtonState="U" and MouseButtonClickLockDownState=1 and Button%Buttons%UnHoldStep=0)
    Button%Buttons%UnHoldStep:=1
  If(ButtonState="D" and MouseButtonClickLockDownState=1 and Button%Buttons%UnHoldStep=1)
    Button%Buttons%UnHoldStep:=2
  
  If (Buttons<=Button)
    Break
}
Return

;Mouse movement support
ButtonDownRight:
MovementVectorDirectionTemp+=1
ButtonDown:
MovementVectorDirectionTemp+=1
ButtonDownLeft:
MovementVectorDirectionTemp+=1
ButtonLeft:
MovementVectorDirectionTemp+=1
ButtonUpLeft:
MovementVectorDirectionTemp+=1
ButtonUp:
MovementVectorDirectionTemp+=1
ButtonUpRight:
MovementVectorDirectionTemp+=1
ButtonRight:
StringReplace, MovementButtonName, A_ThisHotkey, *
If (MovementButtonDown_%MovementButtonName%!=1)
{
  MovementButtonDown_%MovementButtonName%:=1
  MovementVectors:=MovementVectors+1
  MovementVector%MovementVectors%Name:=MovementButtonName
  MovementVector%MovementVectors%Direction:=(MovementVectorDirectionTemp*PI/4)+(MouseRotationAngle*PI/180)
  MovementVector%MovementVectors%Magnitude:=MouseSpeed
  MovementVector%MovementVectors%Initialized:=0
  MovementVector%MovementVectors%UnHoldStep:=0
  If (MovementVectors = 1)
  {
    MouseCurrentAccelerationSpeed:=MouseSpeed
    SetTimer, MovementVectorAcceleration, % MouseAccelerationTimerInterval
  }
}
MovementVectorDirectionTemp:=0
Return

MovementVectorAddition:
;Add 2 vectors
MovementVectorX:=MovementVectorMagnitude*Cos(MovementVectorDirection)+MovementVector%MovementVector%Magnitude*Cos(MovementVector%MovementVector%Direction)
MovementVectorY:=MovementVectorMagnitude*Sin(MovementVectorDirection)+MovementVector%MovementVector%Magnitude*Sin(MovementVector%MovementVector%Direction)
MovementVectorMagnitude:=Sqrt(MovementVectorX**2+MovementVectorY**2)
MovementVectorDirection:=ATan(MovementVectorY/MovementVectorX)
If (MovementVectorX<0)
{
  If (MovementVectorY>0)
    MovementVectorDirection:=MovementVectorDirection-PI
  Else
    MovementVectorDirection:=PI+MovementVectorDirection
}
MovementVectorMagnitudeRatio:=MovementVectorMagnitude/MouseSpeed
Return

MovementVectorAcceleration:
If (MovementVectors=0)
{
  MovementVectorX:=0.000000
  MovementVectorY:=0.000000
  MovementVectorMagnitude:=0.000000
  MovementVectorDirection:=0.000000
  MovementVectorMagnitudeRatio:=0.000000
  MovementResultantVectorMagnitude:=0.000000
  MovementResultantVectorDirection:=0.000000
  MovementResultantVectorX:=0.000000
  MovementResultantVectorY:=0.000000
  ;TrayTip,,% "(" . MovementResultantVectorMagnitude . "," . MovementResultantVectorDirection . ") - <" . MovementResultantVectorX . "," . MovementResultantVectorY . ">"
  SetTimer, MovementVectorAcceleration, off
  Return
}
MovementVector:=0
Loop
{
  MovementVector:=MovementVector+1
  If (MovementVector%MovementVector%Initialized=0)
  {
    Gosub, MovementVectorAddition
    MovementVector%MovementVector%Initialized:=1
  }
  GetKeyState, MovementButtonState, % MovementVector%MovementVector%Name, P
  If (MovementButtonState="U" and (MouseButtonMovementLockDownState=0 or (MouseButtonMovementLockDownState=1 and MovementVector%MovementVector%UnHoldStep=2)))
  {
    MovementButtonName:=MovementVector%MovementVector%Name
    MovementButtonDown_%MovementButtonName%:=0
    MovementVector%MovementVector%Magnitude:=-MovementVector%MovementVector%Magnitude
    Gosub, MovementVectorAddition
    MovementVectorTemp:=MovementVector
    MovementVectorTempPrev:=MovementVector-1
    Loop
    {
      MovementVectorTemp:=MovementVectorTemp+1
      MovementVectorTempPrev:=MovementVectorTempPrev+1
      If (MovementVectors<MovementVectorTemp)
      {
        MovementVector%MovementVectorTempPrev%Name:=""
        MovementVector%MovementVectorTempPrev%Direction:=0
        MovementVector%MovementVectorTempPrev%Magnitude:=0
        MovementVector%MovementVectorTempPrev%Initialized:=0
        MovementVector%MovementVectorTempPrev%UnHoldStep:=0
        Break
      }
      MovementVector%MovementVectorTempPrev%Name:=MovementVector%MovementVectorTemp%Name
      MovementVector%MovementVectorTempPrev%Direction:=MovementVector%MovementVectorTemp%Direction
      MovementVector%MovementVectorTempPrev%Magnitude:=MovementVector%MovementVectorTemp%Magnitude
      MovementVector%MovementVectorTempPrev%Initialized:=MovementVector%MovementVectorTemp%Initialized
      MovementVector%MovementVectorTempPrev%UnHoldStep:=MovementVector%MovementVectorTemp%UnHoldStep
    }
    MovementVectors:=MovementVectors-1
  }
  
  If(MovementButtonState="U" and MouseButtonMovementLockDownState=1 and MovementVector%MovementVector%UnHoldStep=0)
    MovementVector%MovementVector%UnHoldStep:=1
  If(MovementButtonState="D" and MouseButtonMovementLockDownState=1 and MovementVector%MovementVector%UnHoldStep=1)
    MovementVector%MovementVector%UnHoldStep:=2
  
  If (MovementVectors<=MovementVector)
    Break
}
If (MouseCurrentAccelerationSpeed<MouseMaxSpeed)
  MouseCurrentAccelerationSpeed:=MouseCurrentAccelerationSpeed+(MouseAccelerationSpeed/MouseAccelerationCycles)
MovementResultantVectorMagnitude:=MouseCurrentAccelerationSpeed*MovementVectorMagnitudeRatio
MovementResultantVectorDirection:=MovementVectorDirection
MovementResultantVectorX:=MovementResultantVectorMagnitude*Cos(MovementResultantVectorDirection)
MovementResultantVectorY:=MovementResultantVectorMagnitude*Sin(MovementResultantVectorDirection)
;TrayTip,,% "(" . MovementResultantVectorMagnitude . "," . MovementResultantVectorDirection . ") - <" . MovementResultantVectorX . "," . MovementResultantVectorY . ">"
MouseMove, % MovementResultantVectorX, % -MovementResultantVectorY, 0, R
Return

;Mouse wheel movement support
ButtonWheelDownRight:
MovementWheelVectorDirectionTemp+=1
ButtonWheelDown:
MovementWheelVectorDirectionTemp+=1
ButtonWheelDownLeft:
MovementWheelVectorDirectionTemp+=1
ButtonWheelLeft:
MovementWheelVectorDirectionTemp+=1
ButtonWheelUpLeft:
MovementWheelVectorDirectionTemp+=1
ButtonWheelUp:
MovementWheelVectorDirectionTemp+=1
ButtonWheelUpRight:
MovementWheelVectorDirectionTemp+=1
ButtonWheelRight:
StringReplace, MovementWheelButtonName, A_ThisHotkey, *
If (MovementWheelButtonDown_%MovementWheelButtonName%!=1)
{
  MovementWheelButtonDown_%MovementWheelButtonName%:=1
  MovementWheelVectors:=MovementWheelVectors+1
  MovementWheelVector%MovementWheelVectors%Name:=MovementWheelButtonName
  MovementWheelVector%MovementWheelVectors%Direction:=(MovementWheelVectorDirectionTemp*PI/4)+(MouseWheelRotationAngle*PI/180)
  MovementWheelVector%MovementWheelVectors%Magnitude:=MouseWheelSpeed
  MovementWheelVector%MovementWheelVectors%Initialized:=0
  MovementWheelVector%MovementWheelVectors%UnHoldStep:=0
 
  If (MovementWheelVectors = 1)
  {
    MouseWheelCurrentAccelerationSpeed:=MouseWheelSpeed
    SetTimer, MovementWheelVectorAcceleration, % MouseWheelAccelerationTimerInterval
  }
}
MovementWheelVectorDirectionTemp:=0
Return

MovementWheelVectorAddition:
;Add 2 vectors
MovementWheelVectorX:=MovementWheelVectorMagnitude*Cos(MovementWheelVectorDirection)+MovementWheelVector%MovementWheelVector%Magnitude*Cos(MovementWheelVector%MovementWheelVector%Direction)
MovementWheelVectorY:=MovementWheelVectorMagnitude*Sin(MovementWheelVectorDirection)+MovementWheelVector%MovementWheelVector%Magnitude*Sin(MovementWheelVector%MovementWheelVector%Direction)
MovementWheelVectorMagnitude:=Sqrt(MovementWheelVectorX**2+MovementWheelVectorY**2)
MovementWheelVectorDirection:=ATan(MovementWheelVectorY/MovementWheelVectorX)
If (MovementWheelVectorX<0)
{
  If (MovementWheelVectorY>0)
    MovementWheelVectorDirection:=MovementWheelVectorDirection-PI
  Else
    MovementWheelVectorDirection:=PI+MovementWheelVectorDirection
}
MovementWheelVectorMagnitudeRatio:=MovementWheelVectorMagnitude/MouseWheelSpeed
Return

MovementWheelVectorAcceleration:
If (MovementWheelVectors=0)
{
  MovementWheelVectorX:=0.000000
  MovementWheelVectorY:=0.000000
  MovementWheelVectorMagnitude:=0.000000
  MovementWheelVectorDirection:=0.000000
  MovementWheelVectorMagnitudeRatio:=0.000000

  MovementWheelResultantVectorMagnitude:=0.000000
  MovementWheelResultantVectorDirection:=0.000000
  MovementWheelResultantVectorX:=0.000000
  MovementWheelResultantVectorY:=0.000000
 
  ;TrayTip,,% "(" . MovementResultantVectorMagnitude . "," . MovementResultantVectorDirection . ") - <" . MovementResultantVectorX . "," . MovementResultantVectorY . ">"
  SetTimer, MovementWheelVectorAcceleration, off
  Return
}

MovementWheelVector:=0
Loop
{
  MovementWheelVector:=MovementWheelVector+1
  If (MovementWheelVector%MovementWheelVector%Initialized=0)
  {
    Gosub, MovementWheelVectorAddition
    MovementWheelVector%MovementWheelVector%Initialized:=1
  }
 
  GetKeyState, MovementWheelButtonState, % MovementWheelVector%MovementWheelVector%Name, P
  If (MovementWheelButtonState="U" and (MouseButtonMovementLockDownState=0 or (MouseButtonMovementLockDownState=1 and MovementWheelVector%MovementWheelVector%UnHoldStep=2)))
  {
    MovementWheelButtonName:=MovementWheelVector%MovementWheelVector%Name
    MovementWheelButtonDown_%MovementWheelButtonName%:=0
    MovementWheelVector%MovementWheelVector%Magnitude:=-MovementWheelVector%MovementWheelVector%Magnitude
    Gosub, MovementWheelVectorAddition
   
    MovementWheelVectorTemp:=MovementWheelVector
    MovementWheelVectorTempPrev:=MovementWheelVector-1
    Loop
    {
      MovementWheelVectorTemp:=MovementWheelVectorTemp+1
      MovementWheelVectorTempPrev:=MovementWheelVectorTempPrev+1
     
      If (MovementWheelVectors<MovementWheelVectorTemp)
      {
        MovementWheelVector%MovementWheelVectorTempPrev%Name:=""
        MovementWheelVector%MovementWheelVectorTempPrev%Direction:=0
        MovementWheelVector%MovementWheelVectorTempPrev%Magnitude:=0
        MovementWheelVector%MovementWheelVectorTempPrev%Initialized:=0
        MovementWheelVector%MovementWheelVectorTempPrev%UnHoldStep:=0
        Break
      }
     
      MovementWheelVector%MovementWheelVectorTempPrev%Name:=MovementWheelVector%MovementWheelVectorTemp%Name
      MovementWheelVector%MovementWheelVectorTempPrev%Direction:=MovementWheelVector%MovementWheelVectorTemp%Direction
      MovementWheelVector%MovementWheelVectorTempPrev%Magnitude:=MovementWheelVector%MovementWheelVectorTemp%Magnitude
      MovementWheelVector%MovementWheelVectorTempPrev%Initialized:=MovementWheelVector%MovementWheelVectorTemp%Initialized
      MovementWheelVector%MovementWheelVectorTempPrev%UnHoldStep:=MovementWheelVector%MovementWheelVectorTemp%UnHoldStep
    }
    MovementWheelVectors:=MovementWheelVectors-1
  }
  If(MovementWheelButtonState="U" and MouseButtonMovementLockDownState=1 and MovementWheelVector%MovementWheelVector%UnHoldStep=0)
    MovementWheelVector%MovementWheelVector%UnHoldStep:=1
  If(MovementWheelButtonState="D" and MouseButtonMovementLockDownState=1 and MovementWheelVector%MovementWheelVector%UnHoldStep=1)
    MovementWheelVector%MovementWheelVector%UnHoldStep:=2

  If (MovementWheelVectors<=MovementWheelVector)
    Break
}

If (MouseWheelCurrentAccelerationSpeed<MouseWheelMaxSpeed)
  MouseWheelCurrentAccelerationSpeed:=MouseWheelCurrentAccelerationSpeed+(MouseWheelAccelerationSpeed/MouseWheelAccelerationCycles)

MovementWheelResultantVectorMagnitude:=MouseWheelCurrentAccelerationSpeed*MovementWheelVectorMagnitudeRatio
MovementWheelResultantVectorDirection:=MovementWheelVectorDirection
MovementWheelResultantVectorX:=MovementWheelResultantVectorMagnitude*Cos(MovementWheelResultantVectorDirection)
MovementWheelResultantVectorY:=MovementWheelResultantVectorMagnitude*Sin(MovementWheelResultantVectorDirection)
;TrayTip,,% "(" . MovementResultantVectorMagnitude . "," . MovementResultantVectorDirection . ") - <" . MovementResultantVectorX . "," . MovementResultantVectorY . ">"

If (MovementWheelResultantVectorX>=0)
  MouseClick, wheelright,,, % MovementWheelResultantVectorX, 0, D
Else
  MouseClick, wheelleft,,, % -MovementWheelResultantVectorX, 0, D

If (MovementWheelResultantVectorY>=0)
  MouseClick, wheelup,,, % MovementWheelResultantVectorY, 0, D
Else
  MouseClick, wheeldown,,, % -MovementWheelResultantVectorY, 0, D
Return


;Speed/rotation configuration support
;Movement
ButtonSpeedUp:
MouseSpeed:=MouseSpeed+2
ButtonSpeedDown:
MouseSpeed--
If (MouseSpeed>MouseMaxSpeed)
  MouseSpeed:=MouseMaxSpeed
If (MouseSpeed<=1)
{
  MouseSpeed:=1
  ToolTip, Mouse speed: %MouseSpeed% pixel
}
Else
  ToolTip, Mouse speed: %MouseSpeed% pixels
SetTimer, RemoveToolTip, 1000
Return

ButtonAccelerationSpeedUp:
MouseAccelerationSpeed:=MouseAccelerationSpeed+2
ButtonAccelerationSpeedDown:
MouseAccelerationSpeed--
If (MouseAccelerationSpeed<=1)
{
  MouseAccelerationSpeed:=1
  ToolTip, Mouse acceleration speed: %MouseAccelerationSpeed% pixel/cycle
}
Else
  ToolTip, Mouse acceleration speed: %MouseAccelerationSpeed% pixels/cycle
SetTimer, RemoveToolTip, 1000
Return

ButtonMaxSpeedUp:
MouseMaxSpeed:=MouseMaxSpeed+2
ButtonMaxSpeedDown:
MouseMaxSpeed--
If (MouseSpeed>MouseMaxSpeed)
  MouseSpeed:=MouseMaxSpeed
If (MouseMaxSpeed<=1)
{
  MouseMaxSpeed:=1
  ToolTip, Mouse maximum speed: %MouseMaxSpeed% pixel
}
Else
  ToolTip, Mouse maximum speed: %MouseMaxSpeed% pixels
SetTimer, RemoveToolTip, 1000
Return

ButtonRotationAngleUp:
MouseRotationAnglePart:=MouseRotationAnglePart+2
ButtonRotationAngleDown:
MouseRotationAnglePart--
If(MouseRotationAnglePart>=8)
  MouseRotationAnglePart:=0
If(MouseRotationAnglePart<0)
  MouseRotationAnglePart:=7
MouseRotationAngle = %MouseRotationAnglePart%
MouseRotationAngle *= 45
ToolTip, Mouse rotation angle: %MouseRotationAngle%°
SetTimer, RemoveToolTip, 1000
Return

;Wheel
ButtonWheelSpeedUp:
MouseWheelSpeed:=MouseWheelSpeed+2
ButtonWheelSpeedDown:
MouseWheelSpeed--
If (MouseWheelSpeed>MouseWheelMaxSpeed)
  MouseWheelSpeed:=MouseWheelMaxSpeed
If (MouseWheelSpeed<=1)
  MouseWheelSpeed:=1
RegRead, MouseWheelSpeedMultiplier, HKCU, Control Panel\Desktop, WheelScrollLines
MouseWheelSpeedTemp:=MouseWheelSpeed*MouseWheelSpeedMultiplier
If (MouseWheelSpeedTemp=1)
  ToolTip, Mouse wheel speed: %MouseWheelSpeedTemp% line
Else
  ToolTip, Mouse wheel speed: %MouseWheelSpeedTemp% lines
SetTimer, RemoveToolTip, 1000
Return

ButtonWheelAccelerationSpeedUp:
MouseWheelAccelerationSpeed:=MouseWheelAccelerationSpeed+2
ButtonWheelAccelerationSpeedDown:
MouseWheelAccelerationSpeed--
If (MouseWheelAccelerationSpeed<=1)
  MouseWheelAccelerationSpeed:=1
RegRead, MouseWheelSpeedMultiplier, HKCU, Control Panel\Desktop, WheelScrollLines
MouseWheelAccelerationSpeedTemp:=MouseWheelAccelerationSpeed*MouseWheelSpeedMultiplier
If (MouseWheelAccelerationSpeedTemp=1)
  ToolTip, Mouse wheel acceleration speed: %MouseWheelAccelerationSpeedTemp% line/cycle
Else
  ToolTip, Mouse wheel acceleration speed: %MouseWheelAccelerationSpeedTemp% lines/cycle
SetTimer, RemoveToolTip, 1000
Return

ButtonWheelMaxSpeedUp:
MouseWheelMaxSpeed:=MouseWheelMaxSpeed+2
ButtonWheelMaxSpeedDown:
MouseWheelMaxSpeed--
If (MouseWheelSpeed>MouseWheelMaxSpeed)
  MouseWheelSpeed:=MouseWheelMaxSpeed
If (MouseWheelMaxSpeed<=1)
  MouseWheelMaxSpeed:=1
RegRead, MouseWheelSpeedMultiplier, HKCU, Control Panel\Desktop, WheelScrollLines
MouseWheelMaxSpeedTemp:=MouseWheelMaxSpeed*MouseWheelSpeedMultiplier
If (MouseWheelMaxSpeedTemp=1)
  ToolTip, Mouse wheel max speed: %MouseWheelMaxSpeedTemp% line
Else
  ToolTip, Mouse wheel max speed: %MouseWheelMaxSpeedTemp% lines
SetTimer, RemoveToolTip, 1000
Return

ButtonWheelRotationAngleUp:
MouseWheelRotationAnglePart:=MouseWheelRotationAnglePart+2
ButtonWheelRotationAngleDown:
MouseWheelRotationAnglePart--
If(MouseWheelRotationAnglePart>=8)
  MouseWheelRotationAnglePart:=0
If(MouseWheelRotationAnglePart<0)
  MouseWheelRotationAnglePart:=7
MouseWheelRotationAngle = %MouseWheelRotationAnglePart%
MouseWheelRotationAngle *= 45
ToolTip, Mouse wheel rotation angle: %MouseWheelRotationAngle%°
SetTimer, RemoveToolTip, 1000
Return

RemoveToolTip:
SetTimer, RemoveToolTip, Off
ToolTip
Return
Older version can be found at AutoHotkey Script Showcase online.

Complaints, suggestions, questions... are all accepted. Of course, I don't accept to receive new mouse devices, because you know what this script is about... :)

Atomhrt
  • Members
  • 124 posts
  • Last active: Nov 13 2006 09:18 PM
  • Joined: 02 Sep 2004
Pretty cool! I have thrown my mouse into the trash, and I will use the numpad for now on! ;)

I do like the wheel scroll keys *very much*. :)
I am he of whom he speaks!

Gre
  • Members
  • 74 posts
  • Last active: Nov 22 2004 06:23 AM
  • Joined: 12 Oct 2004

I do like the wheel scroll keys *very much*.

Me too!

Hey,deguix.Are you the same person who posted this?

How can I get a number that I want from a REG_SZ string and use it for math operations? I'm using this below:

:O

dijiyd
  • Members
  • 87 posts
  • Last active: Oct 22 2005 01:29 PM
  • Joined: 31 Mar 2004
That is one loooong script. But heckuvalot of help for a few graphics I'm doing. Very nice.

Um.. though, it doesn't seem to support ctrl clicks or alt clicks. Well, nothing a little tweaking can't fix.

deguix
  • Members
  • 87 posts
  • Last active: Jun 17 2014 05:18 AM
  • Joined: 26 Aug 2004

Hey,deguix.Are you the same person who posted this?

I just failed on that... but I got over it afterwards and ended this script which I developed in one week. And I'm still a n00b :roll:.

Um.. though, it doesn't seem to support ctrl clicks or alt clicks. Well, nothing a little tweaking can't fix.

What keys do you suggest instead?

Chris
  • Administrators
  • 10727 posts
  • Last active:
  • Joined: 02 Mar 2004
Great script! And the nice compact help section at the top is a great aid.

And I'm still a n00b :roll:.

Not anymore. This script shows you learned the intricacies very well, such as GetKeyState, dynamic hotkeys, and SetTimer to create an maintain multiple threads.

Um.. though, it doesn't seem to support ctrl clicks or alt clicks. Well, nothing a little tweaking can't fix.

What keys do you suggest instead?

I've spotted some things such as the above that might make this amazing script even better. Here are the details (of course these are only suggestions):

As a first step to supporting ctrl-click and shift-click, insert asterisks (wildcards) in front of the following:
Hotkey, *NumPad0, ButtonLeftClick
Hotkey, *NumPad5, ButtonMiddleClick
Hotkey, *NumPadDot, ButtonRightClick
Hotkey, *NumPadDiv, ButtonX1Click
Hotkey, *NumPadMult, ButtonX2Click
Hotkey, *NumpadSub, ButtonWheelUp
Hotkey, *NumpadAdd, ButtonWheelDown
This next section can be changed to use the above asterisks, as follows:
KeysActivation:
GetKeyState, NumLockState, NumLock, T
If NumLockState = D
{
  Hotkey, *NumpadSub, on
  Hotkey, *NumpadAdd, on

  Hotkey, *NumpadDiv, on
  Hotkey, *NumpadMult, on
}
else
{
  Hotkey, *NumpadSub, off
  Hotkey, *NumpadAdd, off

  Hotkey, *NumpadDiv, off
  Hotkey, *NumpadMult, off
}
return
Also, replace in two places:
Button = %A_ThisHotkey%
with
StringReplace, Button, A_ThisHotkey, *

Finally, to support the above, all GetKeyStates that don't use T (toggle) would have to use P (physical), otherwise if any of them are ever hook hotkeys (such as the wildcard hotkeys), GetKeyState won't report that they're down even though the user is physically holding them down.

To support the ability to shift-left-click, it is necessary to handle the built-in quirks of Numpad, namely that when the user is holding down the shift key, Numlock is effectively off (even though the light is on):
Hotkey, NumpadIns, ButtonShiftLeftClick  ; This must be done to support shift-left-click.
...
ButtonShiftLeftClick:
Button2 = NumPadIns
ButtonClick = Left
Goto ButtonClickStart
...
ButtonClickStart:
If Button2 = NumPadIns
	Send, {shift down}
...

SetTimer, ButtonClickEnd, off
MouseClick, %ButtonClick%,,, 1, 0, U
If Button2 = NumPadIns
	Send, {shift up}
return
To better support control-clicking, it might be worth giving up the following hotkeys in favor of allowing the mouse to move while the user is holding down the control key:
Hotkey, ^Numpad8, ButtonSpeedUp
Hotkey, ^Numpad2, ButtonSpeedDown
Hotkey, ^Numpad7, ButtonAccelerationSpeedUp
Hotkey, ^Numpad1, ButtonAccelerationSpeedDown
Hotkey, ^Numpad9, ButtonMaxSpeedUp
Hotkey, ^Numpad3, ButtonMaxSpeedDown
To better support shift-clicking, consider making NumpadUp/Down/Home/etc. into movement hotkeys. This would allow the user to move the mouse while holding down the shift key. The reason for this is that shift disables Numlock (even though the light may be on).

I noticed you were setting a variable equal to zero. On the off chance that you didn't know, you can make a variable empty this way:
var =
... and check if it's empty this way:
if var =

Also, I think the following line can be removed in two places if you change the "90" that follows it to "90.0":
MouseCurrentSpeedToSide += 0.0

Anyway, I think it's wonderful. I will e-mail you the changed version in case you want it.

With your permission, I would like to post this in the script showcase.

Atomhrt
  • Members
  • 124 posts
  • Last active: Nov 13 2006 09:18 PM
  • Joined: 02 Sep 2004

Anyway, I think it's wonderful. I will e-mail you the changed version in case you want it.


I'd like a copy. Could you email it to me too?
I am he of whom he speaks!

deguix
  • Members
  • 87 posts
  • Last active: Jun 17 2014 05:18 AM
  • Joined: 26 Aug 2004

With your permission, I would like to post this in the script showcase.

OK, you can use your revised version. But is not better to keep the mouse speed adjustment keys rather than the wheel's? Or maybe give them other hotkeys rather than using Ctrl or Alt? The only key not used on the NumPad is the Enter key, so maybe we could be creative and give it an action...

Updated script code on the first post with Chris revised version.

Chris
  • Administrators
  • 10727 posts
  • Last active:
  • Joined: 02 Mar 2004
I'm not sure what's best; I didn't put enough time into it, nor did I test the revised version very well (I was more thinking out loud than trying to force changes to it :)). What might be nice is have the NumpadEnter key popup a menu of choices, or perhaps have it be a prefix key (i.e. hold it down and another key to make an adjustment).

Maybe others who use it will suggest what they think is the best default hotkey configuration.

deguix
  • Members
  • 87 posts
  • Last active: Jun 17 2014 05:18 AM
  • Joined: 26 Aug 2004
Two bugs I found here:

- When holding NumPad5, NumPadDiv or NumPadMult, it clicks several times instead of holding the click. (a problem with MouseClick?)

- Hold a moviment key from NumPad, hold NumLock key, release the movement key and release NumLock. You'll see that that movement continues even when not holding that movement key. This is the same for Shift.

dijiyd
  • Members
  • 87 posts
  • Last active: Oct 22 2005 01:29 PM
  • Joined: 31 Mar 2004
Well, I have a suggestion, why not put the hotkey to enable the mouse_numpad to scroll lock, (not much use for that eh?) then, if numlock is on, you can change the mouse speeds (or vice versa)?

Chris
  • Administrators
  • 10727 posts
  • Last active:
  • Joined: 02 Mar 2004

Two bugs I found here:

- When holding NumPad5, NumPadDiv or NumPadMult, it clicks several times instead of holding the click. (a problem with MouseClick?)

This also happens with left-click and right-click. It is caused by the key-repeat feature. One way to fix it (there may be better ways) is this revised section:
ButtonShiftLeftClick:
GetKeyState, already_down_state, LButton
If already_down_state = D
  return
Button2 = NumPadIns
ButtonClick = Left
Goto ButtonClickStart

ButtonLeftClick:
GetKeyState, already_down_state, LButton
If already_down_state = D
  return
Button2 = NumPad0
ButtonClick = Left
Goto ButtonClickStart

ButtonMiddleClick:
GetKeyState, already_down_state, MButton
If already_down_state = D
  return
Button2 = NumPad5
ButtonClick = Middle
Goto ButtonClickStart

ButtonRightClick:
GetKeyState, already_down_state, RButton
If already_down_state = D
  return
Button2 = NumPadDot
ButtonClick = Right
Goto ButtonClickStart

ButtonX1Click:
GetKeyState, already_down_state, XButton1
If already_down_state = D
  return
Button2 = NumPadDiv
ButtonClick = X1
Goto ButtonClickStart

ButtonX2Click:
GetKeyState, already_down_state, XButton2
If already_down_state = D
  return
Button2 = NumPadMult
ButtonClick = X2
Goto ButtonClickStart

ButtonClickStart:
If Button2 = NumPadIns
  Send, {shift down}
MouseClick, %ButtonClick%,,, 1, 0, D
SetTimer, ButtonClickEnd, 10
return

Hold a moviment key from NumPad, hold NumLock key, release the movement key and release NumLock. You'll see that that movement continues even when not holding that movement key. This is the same for Shift.

I suspect that is "normal" due to the fact that the order in which you press and release the keys can cause a single keystroke's key-down to have a different virtual key code than it's key-up event. AutoHotkey is not designed to deal with keys that change their nature halfway through the keystroke, so the results in a key-state script such as this one may be unpredictable. I'll try to improve this for a future version.

Well, I have a suggestion, why not put the hotkey to enable the mouse_numpad to scroll lock, (not much use for that eh?) then, if numlock is on, you can change the mouse speeds (or vice versa)?

Sounds like a good possibility.

deguix
  • Members
  • 87 posts
  • Last active: Jun 17 2014 05:18 AM
  • Joined: 26 Aug 2004

Well, I have a suggestion, why not put the hotkey to enable the mouse_numpad to scroll lock, (not much use for that eh?) then, if numlock is on, you can change the mouse speeds (or vice versa)?

Ok, at least won't make me hold a key that affects the normal mouse to change to speed adjustments...

Updated code on the first post with Chris' code, and the implementation of the suggestion above.

dijiyd
  • Members
  • 87 posts
  • Last active: Oct 22 2005 01:29 PM
  • Joined: 31 Mar 2004
Hmm.. I tried it, and it looks like there are a few bugs. I'll be tweaking this myself for the bugs, maybe I'll post it later.. (it looks like I'm the only one who needs those modifier clicks :oops:) But here are the things I found:

1. Single clicks left click. This looks like it comes from "ButtonClickStart"

2. Mouse Wheel functions when numlock is on and does not when it is off.

3. Shift clicks don't work because apparently, shift+insert is some kind of universal shortcut for paste. (I dunno. Try it.)

Read ya later..

deguix
  • Members
  • 87 posts
  • Last active: Jun 17 2014 05:18 AM
  • Joined: 26 Aug 2004
I fixed them all. Thanks for that! Updated code on the first post. Now, it has 700+ lines of code. :shock: