InputManager.ahk
Code: Select all
class InputManager
{
static s_Init := False
static s_Moving := False
static s_ForceMouseUpdate := True
static s_UsingReticule := False
static s_ForceReticuleUpdate := True
static s_MoveOnlyKey
static s_RepeatForceMove
static s_HaltMovementOnTarget
static s_MouseOffset
static s_TargetOffset
static s_TargetedKeybinds
static s_MovementKeybinds
static s_PressStack
static s_PressCount
static s_LootDelay
static s_TargetingDelay
static s_HoldDelay
static s_MovementRadius
static s_TargetRadius
static s_MousePos
static s_TargetPos
static s_MouseHidden
static s_Cursor
static s_Reticule
Init()
{
InputManager.s_MoveOnlyKey := IniReader.ParseKeybind(IniReader.ReadKeybindingKey(KeybindingSection.Keybindings, "Force_Move"))
InputManager.s_RepeatForceMove := IniReader.ReadProfileKey(ProfileSection.Preferences, "Repeat_Force_Move")
InputManager.s_HaltMovementOnTarget := IniReader.ReadProfileKey(ProfileSection.Preferences, "Halt_Movement_On_Target")
InputManager.s_MouseOffset
:= new Vector2(IniReader.ReadProfileKey(ProfileSection.AnalogStick, "Movement_Center_Offset_X")
, IniReader.ReadProfileKey(ProfileSection.AnalogStick, "Movement_Center_Offset_Y"))
InputManager.s_TargetOffset
:= new Vector2(IniReader.ReadProfileKey(ProfileSection.AnalogStick, "Targeting_Center_Offset_X")
, IniReader.ReadProfileKey(ProfileSection.AnalogStick, "Targeting_Center_Offset_Y"))
InputManager.s_TargetedKeybinds := IniReader.ParseKeybindArray("Targeted_Actions")
InputManager.s_MovementKeybinds := IniReader.ParseKeybindArray("Movement_Actions")
InputManager.s_PressStack := new LooseStack()
InputManager.s_PressCount := new PressCounter()
InputManager.s_LootDelay := IniReader.ReadProfileKey(ProfileSection.Preferences, "Loot_Delay")
InputManager.s_TargetingDelay := IniReader.ReadProfileKey(ProfileSection.Preferences, "Targeting_Delay")
InputManager.s_HoldDelay := IniReader.ReadProfileKey(ProfileSection.Preferences, "Hold_Delay")
InputManager.s_MovementRadius
:= new Rect(new Vector2(IniReader.ReadProfileKey(ProfileSection.AnalogStick, "Movement_Min_Radius_Width")
, IniReader.ReadProfileKey(ProfileSection.AnalogStick, "Movement_Min_Radius_Height"))
, new Vector2(IniReader.ReadProfileKey(ProfileSection.AnalogStick, "Movement_Max_Radius_Width")
, IniReader.ReadProfileKey(ProfileSection.AnalogStick, "Movement_Max_Radius_Height")))
InputManager.s_TargetRadius
:= new Rect(new Vector2(IniReader.ReadProfileKey(ProfileSection.AnalogStick, "Targeting_Min_Radius_Width")
, IniReader.ReadProfileKey(ProfileSection.AnalogStick, "Targeting_Min_Radius_Height"))
, new Vector2(IniReader.ReadProfileKey(ProfileSection.AnalogStick, "Targeting_Max_Radius_Width")
, IniReader.ReadProfileKey(ProfileSection.AnalogStick, "Targeting_Max_Radius_Height")))
InputManager.s_MousePos := InputHelper.GetMousePos()
;InputManager.s_TargetPos := CriticalObject(InputHelper.GetMousePos())
InputManager.s_MouseHidden := True
InputManager.s_Cursor := new Image("Images\diabloCursor.png")
InputManager.s_Reticule := new Image("Images\Target.png")
;this.ChildInit()
InputManager.s_Init := True
}
; Create accessors for children
m_Init[] {
get {
return InputManager.s_Init
}
}
m_Moving[] {
get {
return InputManager.s_Moving
}
}
m_ForceMouseUpdate[] {
get {
return InputManager.s_ForceMouseUpdate
}
}
m_UsingReticule[] {
get {
return InputManager.s_UsingReticule
}
}
m_ForceReticuleUpdate[] {
get {
return InputManager.s_ForceReticuleUpdate
}
}
m_MoveOnlyKey[] {
get {
return InputManager.s_MoveOnlyKey
}
}
m_RepeatForceMove[] {
get {
return InputManager.s_RepeatForceMove
}
}
m_HaltMovementOnTarget[] {
get {
return InputManager.s_HaltMovementOnTarget
}
}
m_MouseOffset[] {
get {
return InputManager.s_MouseOffset
}
}
m_TargetOffset[] {
get {
return InputManager.s_TargetOffset
}
}
m_TargetedKeybinds[] {
get {
return InputManager.s_TargetedKeybinds
}
}
m_MovementKeybinds[] {
get {
return InputManager.s_MovementKeybinds
}
}
m_PressStack[] {
get {
return InputManager.s_PressStack
}
}
m_PressCount[] {
get {
return InputManager.s_PressCount
}
}
m_LootDelay[] {
get {
return InputManager.s_LootDelay
}
}
m_TargetingDelay[] {
get {
return InputManager.s_TargetingDelay
}
}
m_HoldDelay[] {
get {
return InputManager.s_HoldDelay
}
}
m_MovementRadius[] {
get {
return InputManager.s_MovementRadius
}
}
m_TargetRadius[] {
get {
return InputManager.s_TargetRadius
}
}
m_MousePos[] {
get {
return InputManager.s_MousePos
}
set {
return InputManager.s_MousePos := value
}
}
m_TargetPos[] {
get {
return InputManager.s_TargetPos
}
set {
return InputManager.s_TargetPos := value
}
}
m_MouseHidden[] {
get {
return InputManager.s_MouseHidden
}
}
m_Cursor[] {
get {
return InputManager.s_Cursor
}
}
m_Reticule[] {
get {
return InputManager.s_Reticule
}
}
ChildInit() {
}
}
Code: Select all
; Intercepts keyboard and mouse input and manipulates it
class Intercept extends InputManager
{
static m_Up := False
static m_Down := False
static m_Left := False
static m_Right := False
static m_PrevMovement := new Vector2()
static m_Movement := new Vector2()
static m_Reticule
ChildInit()
{
global
BlockInput, MouseMove
this.m_Reticule := new Image("Images\Target.png")
; TODO Loop through movement inputs
; Up inputs
local fn := ObjBindMethod(Intercept, "MovePress", "Up")
hotkey, $w, % fn
local fn := ObjBindMethod(Intercept, "MoveRelease", "Up")
hotkey, $w Up, % fn
; Down inputs
local fn := ObjBindMethod(Intercept, "MovePress", "Down")
hotkey, $s, % fn
local fn := ObjBindMethod(Intercept, "MoveRelease", "Down")
hotkey, $s Up, % fn
; Left inputs
local fn := ObjBindMethod(Intercept, "MovePress", "Left")
hotkey, $a, % fn
local fn := ObjBindMethod(Intercept, "MoveRelease", "Left")
hotkey, $a Up, % fn
; Right Inputs
local fn := ObjBindMethod(Intercept, "MovePress", "Right")
hotkey, $d, % fn
local fn := ObjBindMethod(Intercept, "MoveRelease", "Right")
hotkey, $d Up, % fn
; TODO Loop through Targeted Skills
local _keybind := IniReader.ParseKeybind("q")
_keybind.Type := KeybindType.Targeted
local fn := ObjBindMethod(Intercept, "TargetedPress", _keybind)
hotkey, $q, % fn
local fn := ObjBindMethod(Intercept, "TargetedRelease", _keybind)
hotkey, $q Up, % fn
local fn := ObjBindMethod(Intercept, "TargetedPress", IniReader.ParseKeybind("LButton"))
hotkey, $LButton, % fn
local fn := ObjBindMethod(Intercept, "TargetedRelease", IniReader.ParseKeybind("LButton"))
hotkey, $LButton Up, % fn
local fn := ObjBindMethod(Intercept, "TargetedPress", IniReader.ParseKeybind("Shift+LButton"))
hotkey, $+LButton, % fn
local fn := ObjBindMethod(Intercept, "TargetedRelease", IniReader.ParseKeybind("Shift+LButton"))
hotkey, $+LButton Up, % fn
local fn := ObjBindMethod(Intercept, "TargetedPress", IniReader.ParseKeybind("RButton"))
hotkey, $RButton, % fn
local fn := ObjBindMethod(Intercept, "TargetedRelease", IniReader.ParseKeybind("RButton"))
hotkey, $RButton Up, % fn
AHKThread("
(
#Include Input\MouseThread.ahk
)", &this.m_TargetPos "")
this.m_CurrTime := FPS.GetCurrentTime()
this.m_PrevTime := this.m_CurrTime
Debug.OnToolTipAddListener(new Delegate(Intercept, "OnToolTip"))
}
Update()
{
global
this.m_PrevMovement := this.m_Movement.Clone()
this.m_Movement := new Vector2()
if (this.m_Up)
this.m_Movement.Y -= 1
if (this.m_Down)
this.m_Movement.Y += 1
if (this.m_Left)
this.m_Movement.X -= 1.5
if (this.m_Right)
this.m_Movement.X += 1.5
if (!Vector2.IsEqual(this.m_Movement, this.m_PrevMovement))
{
local _centerOffset
:= Vector2.Add(Vector2.Add(Graphics.ActiveWinStats.Pos, Graphics.ActiveWinStats.Center)
, Vector2.Mul(this.m_MouseOffset, Graphics.ResolutionScale))
InputHelper.MoveMouse(Vector2.Add(_centerOffset, Vector2.Mul(this.m_Movement, 50)))
if (!Vector2.IsEqual(this.m_Movement, Vector2.Zero))
InputHelper.PressKeybind(this.m_MoveOnlyKey)
else
InputHelper.ReleaseKeybind(this.m_MoveOnlyKey)
}
this.m_Reticule.Draw(this.m_TargetPos)
}
TargetedPress(p_Keybind)
{
InputHelper.PressKeybind(p_Keybind)
}
TargetedRelease(p_Keybind)
{
InputHelper.ReleaseKeybind(p_Keybind)
}
MovePress(p_Direction)
{
if (p_Direction = "Up")
this.m_Up := True
if (p_Direction = "Down")
this.m_Down := True
if (p_Direction = "Left")
this.m_Left := True
if (p_Direction = "Right")
this.m_Right := True
}
MoveRelease(p_Direction)
{
if (p_Direction = "Up")
this.m_Up := False
if (p_Direction = "Down")
this.m_Down := False
if (p_Direction = "Left")
this.m_Left := False
if (p_Direction = "Right")
this.m_Right := False
}
; MouseEvent(p_MouseID, p_X := 0, p_Y := 0)
; {
; global
; static _carryX := 0, _carryY := 0, _mainMouse
; if (p_MouseID = 0 or (_mainMouse and p_MouseID != _mainMouse))
; return
; _mainMouse := p_MouseID
; this.m_PrevTime := this.m_CurrTime
; this.m_CurrTime := FPS.GetCurrentTime()
; local _deltaTime := Min(this.m_CurrTime - this.m_PrevTime, FPS.Delay)
; ; Pre-scale
; p_X *= 3
; p_Y *= 3
; ; Speedcap
; if (False)
; {
; local _rate := Sqrt(p_X * p_X + p_Y * p_Y)
; if (_rate >= 10)
; {
; }
; }
; ; Acceleration
; local _accelSens := 1
; if (True)
; {
; local _rate := Sqrt(p_X * p_X + p_Y * p_Y) / _deltaTime
; _rate -= 1
; if (_rate > 0)
; {
; _rate *= 1.5
; local _power = Max(2 - 1, 0)
; _accelSens += Exp(_power * Log(_rate))
; }
; }
; _accelSens /= 1
; p_X *= _accelSens
; p_Y *= _accelSens
; p_X *= _deltaTime / 1000
; p_Y *= _deltaTime / 1000
; p_X *= 50
; p_Y *= 50
; this.m_DeltaMouse := new Vector2(p_X, p_Y)
; this.m_CursorPos := Vector2.Add(this.m_CursorPos, this.m_DeltaMouse)
; this.m_Reticule.Draw(this.m_CursorPos)
; }
OnToolTip()
{
global
local _debugText :=
_debugText .= "CursorPos: " . this.m_TargetPos.String . " Movement" . this.m_Movement.String
return _debugText
}
}
Code: Select all
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
#SingleInstance Force
;#Persistent ; Keep this script running until the user explicitly exits it.
#MaxHotkeysPerInterval 99000000
#HotkeyInterval 99000000
#MaxThreads 255
#KeyHistory 0
ListLines Off
Process, Priority, , A
SetBatchLines, -1
#Include Library\MouseDelta.ahk
#Include Library\Delegate.ahk
_critObj := CriticalObject(A_Args[1])
_function := new MouseDelta(new Delegate("MouseEvent"))
_function.SetState(1)
return
MouseEvent(p_MouseID, p_X := 0, p_Y := 0)
{
global
static _carryX := 0, _carryY := 0, _mainMouse
if (p_MouseID = 0 or (_mainMouse and p_MouseID != _mainMouse))
return
_mainMouse := p_MouseID
_critObj.X += p_X
_critObj.Y += p_Y
}
The second part that is probably causing problems is the fact that I'm extending from InputManager. I do this because there is another class 'Controller.ahk' which is disabled right now but will be reading from the same static values and also extends from InputManager.
The goal is to have a separate thread receive raw mouse input and send it back to the main thread. That way I can BlockInput, MouseMove while still processing mouse input.
This is part of a larger project which converts joystick input to mouse and keyboard macros. This new bit is to change WASD to mouse input while having a software cursor act as a sort of targeting reticule for other keyboard actions which need the mouse to function.