Jump to content

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

Mouse Movement to Keypress


  • Please log in to reply
49 replies to this topic
Michigraf
  • Members
  • 9 posts
  • Last active: Nov 28 2014 05:30 PM
  • Joined: 11 Dec 2012

hello

 

my name is michi and i am new at autohotkey. i've got many diffrent games who only can be played by keyboard (and i am have a big handycap). what i need is a script that transform mouse movements into key presses.

 

a kind like that:

 

as long as i move the mouse to the left, it press and hold e.g the left arrowkey. same for right, up and down. 

 

can anyone help me?

 

greets 

 

michi (from switzerland, so sorry for bad englisch)



Pulover
  • Members
  • 1596 posts
  • Last active: Apr 06 2016 04:00 AM
  • Joined: 20 Apr 2012
Hi, Michi! Welcome to the forums! You probably need Mouse Gestures. It comes in the Help File Script showcase. http://www.autohotke...useGestures.htm

Rodolfo U. Batista
Pulover's Macro Creator - Automation Tool (Recorder & Script Writer) | Class_LV_Rows - Copy, Cut, Paste and Drag ListViews | Class_Toolbar - Create and modify | Class_Rebar - Adjustable GUI controls

Join the New AutoHotkey Forum!


strobo
  • Members
  • 359 posts
  • Last active: Mar 10 2015 08:13 PM
  • Joined: 19 Jun 2012

From

http://www.autohotke...gesture-script/

You may use Mouse_Gesture. E.g:

Edit: I just realized, Mouse_Gesture is not suited for your needs pressing wasd or arrows.


Regards,
Babba

Oby
  • Members
  • 11 posts
  • Last active: Jan 31 2013 04:52 PM
  • Joined: 10 Dec 2012
I am also interested if it is possible to do this.
I tested mouse gesture I also find that it is not suitable


Pulover
  • Members
  • 1596 posts
  • Last active: Apr 06 2016 04:00 AM
  • Joined: 20 Apr 2012
I see... in this case (since I couldn't find anything like this in my searchs) I volunteer to create such script.

I will start coding and testing. As soon as I got something working I will post for you to try and we can improve it as you need.

:)

Rodolfo U. Batista
Pulover's Macro Creator - Automation Tool (Recorder & Script Writer) | Class_LV_Rows - Copy, Cut, Paste and Drag ListViews | Class_Toolbar - Create and modify | Class_Rebar - Adjustable GUI controls

Join the New AutoHotkey Forum!


None
  • Members
  • 3199 posts
  • Last active: Nov 05 2015 09:55 PM
  • Joined: 28 Nov 2009

While holding Left Control Movements of the mouse Send WASD

LCtrl::
MouseGetPos, VarX, VarY
While GetKeyState("LCtrl","p")
{
Sleep 150
MouseGetPos, NVarX, NVarY
If (VarX=NVarX) and (VarY=NVary)
 Continue
Send % (NVarY<(NVarX-(VarX-VarY))) ? (NVarY<(-NVarX+(VarX+VarY))) 
? "w" : "d" : (NVarY>(-NVarX+(VarX+VarY))) ? "s" : "a"
VarX:=NVarX,VarY:=NVary
}
Return
 


Pulover
  • Members
  • 1596 posts
  • Last active: Apr 06 2016 04:00 AM
  • Joined: 20 Apr 2012
Here's my version. My idea was to divide the screen in 9 rectangles, the one at the center is a Dead Zone, and the ones around it can be configured to send the keys.
This script presses and holds the keys instead of repeatedly send them, and releases it when the zone is changed.

Instructions:
  • Configure the hotkeys to activate/deactivate the function.
  • Configure the hotkey to show the Dead Zone area.
  • Configure a key to instantly return mouse cursor to the center of the screen (optional).
  • Set the size of the Dead Zone (Horizontal and Vertical ranges).
  • Configure the keys to be sent for each area of the screen.
  • You can set more then one key by separating them with a '&'.
;==========================================================================
;
; 				MouseSendZones
;
; Author:		Pulover [Rodolfo U. Batista]
;				[email protected]
;
; Description:	This script sends user-defined keys when the mouse is
; 				over an area of the screen by creating a rectangle at
; 				the center to be the Dead Zone and 8 other rectangles
; 				around it, each one will send and hold the configured
; 				keys when the mouse hovers over it.
;
;==========================================================================

; ########## Configurations: ##########

; Select Hotkey to active the funtion:
Activate = ~LControl

; Select Hotkey show Zones Guidelcines:
ShowZones = CapsLock

; Select optional Hotkey reset mouse to Center:
Center = MButton

; Set Horizontal & Vertical Dead Zone Ranges in pixels:
DeadZoneRangeX := 200
DeadZoneRangeY := 150

KeySet =
( ; Set the keys that will be sent for each of the eight zones of the screen:
Up = Up
Down = Down
Left = Left
Right = Right
UpLeft = Up & Left
UpRight = Up & Right
DownLeft = Down & Left
DownRight = Down & Right
)

; ########## End of configurations! ##########

; Parse KeySet and assign variables to the keys:
Loop, Parse, KeySet, `n
{
	Loop, Parse, A_LoopField, =, %A_Space%
		If Mod(A_Index, 2)
			Key := A_LoopField
		Else
		{
			%Key% := A_LoopField
			StringSplit, %Key%, A_LoopField, &, %A_Space%
		}
}

#SingleInstance, Force
SendMode, Input
SetKeyDelay, -1
SetMouseDelay, -1
SetBatchLines, -1
CoordMode, Mouse, Screen

; Get the coordinates for the center of the screen to create a Dead Zone:
DeadZoneX := A_ScreenWidth / 2
DeadZoneY := A_ScreenHeight / 2

; Activate Hotkeys:
Hotkey, %Activate%, Activate, On
Hotkey, %ShowZones%, ShowZones, On
Try Hotkey, %Center%, CenterMouse, On

; Create a rectangle to show Dead Zone:
A := DeadZoneRangeX*2, B := DeadZoneRangeY*2, C := A-2, D := B-2

Gui, -Caption +ToolWindow +LastFound +AlwaysOnTop
Gui, Color, Red
Gui, +LastFound
WinSet, Region, 0-0 %A%-0 %A%-%B% 0-%B% 0-0  2-2 %C%-2 %C%-%D% 2-%D% 2-2
GoSub, ShowZones
Display := !Display
SetTimer, RemoveTip, -1500
return

Activate:
SetTimer, WatchMouse, % (Active := !Active) ? 0 : "Off"
Loop, % %hKeys%0
	Send, %  (hKeys = "DeadZone") ? "" : "{" %hKeys%%A_Index% " up}"
return

ShowZones:
If (Display := !Display)
{
	Gui, Show, % "NA x" DeadZoneX - DeadZoneRangeX "y" DeadZoneY - DeadZoneRangeY "w" DeadZoneRangeX * 2 "h" DeadZoneRangeY * 2
	Tooltip, Dead Zone, % DeadZoneX-25, % DeadZoneY-25, 1
	Tooltip, % Up, % DeadZoneX-25, % 0, 2
	Tooltip, % Down, % DeadZoneX-25, % A_ScreenHeight, 3
	Tooltip, % Left, % 0, % DeadZoneY-25, 4
	Tooltip, % Right, % A_ScreenWidth, % DeadZoneY-25, 5
	Tooltip, % UpLeft, % 0, % 0, 6
	Tooltip, % UpRight, % A_ScreenWidth, % 0, 7
	Tooltip, % DownLeft, % 0, % A_ScreenHeight, 8
	Tooltip, % DownRight, % A_ScreenWidth, % A_ScreenHeight, 9
}
Else
	GoSub, RemoveTip
return

RemoveTip:
Gui, Cancel
Tooltip,,,,1
Tooltip,,,,2
Tooltip,,,,3
Tooltip,,,,4
Tooltip,,,,5
Tooltip,,,,6
Tooltip,,,,7
Tooltip,,,,8
Tooltip,,,,9
return

CenterMouse:
Click, %DeadZoneX%, %DeadZoneY%, 0
return

WatchMouse:
MouseGetPos, pX, pY
zKeys := GetZone(pX, pY, DeadZoneX, DeadZoneY, DeadZoneRangeX, DeadZoneRangeY)
If (hKeys <> zKeys)
{
	Loop, % %hKeys%0
		Send, %  (hKeys = "DeadZone") ? "" : "{" %hKeys%%A_Index% " up}"
	Loop, % %zKeys%0
		Send, % (zKeys = "DeadZone") ? "" : "{" %zKeys%%A_Index% "  down}"
	hKeys := zKeys
}
return

GetZone(X, Y, DX, DY, RX, RY)
{
	If (Y < (DY - RY))
		Zone .= "Up"
	If (Y > (DY + RY))
		Zone .= "Down"
	If (X > (DX + RX))
		Zone .= "Right"
	If (X < (DX - RX))
		Zone .= "Left"
	return Zone = "" ? "DeadZone" : Zone
}

Rodolfo U. Batista
Pulover's Macro Creator - Automation Tool (Recorder & Script Writer) | Class_LV_Rows - Copy, Cut, Paste and Drag ListViews | Class_Toolbar - Create and modify | Class_Rebar - Adjustable GUI controls

Join the New AutoHotkey Forum!


Michigraf
  • Members
  • 9 posts
  • Last active: Nov 28 2014 05:30 PM
  • Joined: 11 Dec 2012

Here's my version. My idea was to divide the screen in 9 rectangles, the one at the center is a Dead Zone, and the ones around it can be configured to send the keys.
This script presses and holds the keys instead of repeatedly send them, and releases it when the zone is changed.

 

Hello Thanks you. it works well, but a improvment would make it perfect for my use:

 

when i no longer move the mouse, it should reset the mouse to center. short: autocenter after mouse stops move. like None's script but with houlding the keys.

 

greets michi



Pulover
  • Members
  • 1596 posts
  • Last active: Apr 06 2016 04:00 AM
  • Joined: 20 Apr 2012
Well, I thought the hover method would be more suitable for games... Are you sure the MButton reset is not better? You can set any key you want and just press it to center the mouse.
I think I might be able to adapt the script to reset the mouse when it stops, but I think it would not be of much help when you need to hold a key for a longer time, I mean, what should happen if you hit an edge of the screen?

Rodolfo U. Batista
Pulover's Macro Creator - Automation Tool (Recorder & Script Writer) | Class_LV_Rows - Copy, Cut, Paste and Drag ListViews | Class_Toolbar - Create and modify | Class_Rebar - Adjustable GUI controls

Join the New AutoHotkey Forum!


Oby
  • Members
  • 11 posts
  • Last active: Jan 31 2013 04:52 PM
  • Joined: 10 Dec 2012

Hello

For me the still method works well but it is not practical in all the games. Especially that sometimes the mouse cursor thus disappears that leaves fast in all directions.

In games which looks like Diablo that does not really raise problem.
But in type FPS's games, that raises big problems because generally the mouse is assigned to the movements of camera.
Thus that you want to move forward there is a camera which goes upward.

For I play a simulation of flight, I would want that the mouse react as a joystick.

I also tried the method to none but it is not rather reactive 

But thank you anyway for it is first script



Pulover
  • Members
  • 1596 posts
  • Last active: Apr 06 2016 04:00 AM
  • Joined: 20 Apr 2012
Ok, so before I go on with a new version let's number the requests and decide the more appropriate behavior.

1. Should the keys be sent by hovering an area or by keep moving the mouse? In case of the second I would like to know what's not woking so well with None's script.
2. Should the mouse real movements be blocked during send?
3. Should the activate key toggle the function or should it work while the key is being held?

Or maybe we should have both versions assigned to different hotkeys?

Rodolfo U. Batista
Pulover's Macro Creator - Automation Tool (Recorder & Script Writer) | Class_LV_Rows - Copy, Cut, Paste and Drag ListViews | Class_Toolbar - Create and modify | Class_Rebar - Adjustable GUI controls

Join the New AutoHotkey Forum!


Michigraf
  • Members
  • 9 posts
  • Last active: Nov 28 2014 05:30 PM
  • Joined: 11 Dec 2012

1. : None's script dont work because it repeatedly send the key. i testet it in a game and i cannot walk with it. with normal key controll you must hold the key for walk.

the reason why i prefer the keeping moving-method is, that i got a wheelchair, where the joystick act like a mouse.

 

2. : for my use, it is not necessary.

 

3. : toggle the function is better for me

 

greetings michi



Pulover
  • Members
  • 1596 posts
  • Last active: Apr 06 2016 04:00 AM
  • Joined: 20 Apr 2012
Alright, now that I got the picture I'll see if I can come up with something that would be suitable for both of you.

Rodolfo U. Batista
Pulover's Macro Creator - Automation Tool (Recorder & Script Writer) | Class_LV_Rows - Copy, Cut, Paste and Drag ListViews | Class_Toolbar - Create and modify | Class_Rebar - Adjustable GUI controls

Join the New AutoHotkey Forum!


Pulover
  • Members
  • 1596 posts
  • Last active: Apr 06 2016 04:00 AM
  • Joined: 20 Apr 2012
So here's a new version with both Hover and Stick methods. You can switch between them using hotkeys.
One thing I cannot figure out how it would work: move the mouse to send keystrokes but still avoid camera movements... this seems rather illogical to me. Or does anyone know how this is possible?

Let me know how it goes now.

;==========================================================================
;
; 				MouseSendZones
;
; Author:		Pulover [Rodolfo U. Batista]
;				[email protected]
;
; HoverMode:	The script sends user-defined keys when the mouse is
;				over an area of the screen by creating a rectangle at
;				the center to be the Dead Zone and 8 other rectangles
;				around it, each one will send and hold the configured
;				keys when the mouse hovers over it.
;
; StickMode:	When the mouse is moved in one direction the script
;				sends the corresponding keys and releases them when
;				it stops moving. This is more specific for using a
;				joystick to control mouse movements.
;
;==========================================================================

; ########## Configurations: ##########

; Select Hotkey to active HoverMode:
Hover = F1

; Select Hotkey to active StickMode:
Stick = F2

; Select Hotkey show Zones Guidelcines:
ShowZones = CapsLock

; Select optional Hotkey reset mouse to Center:
Center = MButton

; Set Horizontal & Vertical Dead Zone Ranges in pixels:
DeadZoneRangeX := 200
DeadZoneRangeY := 150

KeySet =
( ; Set the keys that will be sent for each of the eight zones of the screen:
Up = Up
Down = Down
Left = Left
Right = Right
UpLeft = Up & Left
UpRight = Up & Right
DownLeft = Down & Left
DownRight = Down & Right
)

; ########## End of configurations! ##########

; Parse KeySet and assign variables to the keys:
Loop, Parse, KeySet, `n
{
	Loop, Parse, A_LoopField, =, %A_Space%
		If Mod(A_Index, 2)
			Key := A_LoopField
		Else
		{
			%Key% := A_LoopField
			StringSplit, %Key%, A_LoopField, &, %A_Space%
		}
}

#SingleInstance, Force
SendMode, Input
SetKeyDelay, -1
SetMouseDelay, -1
SetBatchLines, -1
CoordMode, Mouse, Screen

; Get coordinates for the center of the screen to create a Dead Zone:
DeadZoneX := A_ScreenWidth / 2
DeadZoneY := A_ScreenHeight / 2

; Activate Hotkeys:
Hotkey, %Hover%, Hover, On
Hotkey, %Stick%, Stick, On
Hotkey, %ShowZones%, ShowZones, On
Try Hotkey, %Center%, CenterMouse, On

; Create a rectangle to show Dead Zone:
A := DeadZoneRangeX*2, B := DeadZoneRangeY*2, C := A-2, D := B-2

Gui, -Caption +ToolWindow +LastFound +AlwaysOnTop
Gui, Color, Red
Gui, +LastFound
WinSet, Region, 0-0 %A%-0 %A%-%B% 0-%B% 0-0  2-2 %C%-2 %C%-%D% 2-%D% 2-2
GoSub, ShowZones
Display := !Display
SetTimer, RemoveTip, -1500
return

Hover:
StickMode := False
SetTimer, WatchMouse, % (HoverMode := !HoverMode) ? 0 : "Off"
Loop, % %hKeys%0
	Send, %  (hKeys = "DeadZone") ? "" : "{" %hKeys%%A_Index% " up}"
TrayTip,, % (HoverMode) ? "HoverMode On" : "HoverMode Off"
return

Stick:
HoverMode := False
SetTimer, WatchMouse, % (StickMode := !StickMode) ? 0 : "Off"
Loop, % %hKeys%0
	Send, %  (hKeys = "DeadZone") ? "" : "{" %hKeys%%A_Index% " up}"
TrayTip,, % (StickMode) ? "StickMode On" : "StickMode Off"
return

ShowZones:
If (Display := !Display)
{
	Gui, Show, % "NA x" DeadZoneX - DeadZoneRangeX "y" DeadZoneY - DeadZoneRangeY "w" DeadZoneRangeX * 2 "h" DeadZoneRangeY * 2
	Tooltip, Dead Zone, % DeadZoneX-25, % DeadZoneY-25, 1
	Tooltip, % Up, % DeadZoneX-25, % 0, 2
	Tooltip, % Down, % DeadZoneX-25, % A_ScreenHeight, 3
	Tooltip, % Left, % 0, % DeadZoneY-25, 4
	Tooltip, % Right, % A_ScreenWidth, % DeadZoneY-25, 5
	Tooltip, % UpLeft, % 0, % 0, 6
	Tooltip, % UpRight, % A_ScreenWidth, % 0, 7
	Tooltip, % DownLeft, % 0, % A_ScreenHeight, 8
	Tooltip, % DownRight, % A_ScreenWidth, % A_ScreenHeight, 9
}
Else
	GoSub, RemoveTip
return

RemoveTip:
Gui, Cancel
Tooltip,,,,1
Tooltip,,,,2
Tooltip,,,,3
Tooltip,,,,4
Tooltip,,,,5
Tooltip,,,,6
Tooltip,,,,7
Tooltip,,,,8
Tooltip,,,,9
return

CenterMouse:
Click, %DeadZoneX%, %DeadZoneY%, 0
return

WatchMouse:
MouseGetPos, pX, pY
If StickMode
{
	If ((pX = 0) || (pX = A_ScreenWidth-1))
		|| ((pY = 0) || (pY = A_ScreenHeight-1))
		GoSub, CenterMouse
	Sleep, 150
	MouseGetPos, cX, cY
	zKeys := MoveZone(pX, pY, cX, cY)
}
Else
	zKeys := GetZone(pX, pY, DeadZoneX, DeadZoneY, DeadZoneRangeX, DeadZoneRangeY)
If (hKeys <> zKeys)
{
	Loop, % %hKeys%0
		Send, %  (hKeys = "DeadZone") ? "" : "{" %hKeys%%A_Index% " up}"
	Loop, % %zKeys%0
		Send, % (zKeys = "DeadZone") ? "" : "{" %zKeys%%A_Index% "  down}"
	hKeys := zKeys
}
return

GetZone(X, Y, DX, DY, RX, RY)
{
	If (Y < (DY - RY))
		Zone .= "Up"
	If (Y > (DY + RY))
		Zone .= "Down"
	If (X < (DX - RX))
		Zone .= "Left"
	If (X > (DX + RX))
		Zone .= "Right"
	return Zone = "" ? "DeadZone" : Zone
}

MoveZone(pX, pY, cX, cY)
{
	If (cY < pY)
		Zone .= "Up"
	If (cY > pY)
		Zone .= "Down"
	If (cX < pX)
		Zone .= "Left"
	If (cX > pX)
		Zone .= "Right"
	return Zone = "" ? "DeadZone" : Zone
}

Rodolfo U. Batista
Pulover's Macro Creator - Automation Tool (Recorder & Script Writer) | Class_LV_Rows - Copy, Cut, Paste and Drag ListViews | Class_Toolbar - Create and modify | Class_Rebar - Adjustable GUI controls

Join the New AutoHotkey Forum!


strobo
  • Members
  • 359 posts
  • Last active: Mar 10 2015 08:13 PM
  • Joined: 19 Jun 2012
... where the joystick act like a mouse.

 

Maybe, AHK can read the joystick axes directly. Then, uncoupling Joystick from Mouse Cursor (when needed) would be the next issue (mapping a joystick to keys is already solved). For tha,t the command BlockInput would be worth trying... But first things first! To test, you can run a Joystick Test Script from the documentation, here is one:

; 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


Regards,
Babba