AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Invert mouse axis

 
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Ask for Help
View previous topic :: View next topic  
Author Message
Frans
Guest





PostPosted: Sun May 20, 2007 8:01 pm    Post subject: Invert mouse axis Reply with quote

Hello all,

I'm busy with a project for school and fabricated a mouse-like device, that is, it doesn't look like a mouse, but has a ps2 connector and moves my cursor very nicely around the screen...unfortinately I haven't been so smart and now figured out that I need to invert the mouse axis, or rebuild the thing.

I found on internet a file which should invert the axis, but doesn't work for me...
; Script for AutoHotKeys, http://autohotkey.com/
; Inverts the mouse along the y axis. Works great, but not in games or other
; apps that use DirectInput. :/

#SingleInstance
#Persistent

SetBatchLines, 10ms
;CoordMode, Mouse, Screen
BlockInput, Mouse
SetMouseDelay, -1 ; Makes movement smoother.

oldy = 0 ; initial value
SetTimer, WatchMouse, 1
return

WatchMouse:
IfWinNotActive, Beyond Good & Evil - Ubisoft
return

MouseGetPos, x, y,

delta = %y%
delta -= %oldy%
if delta <> 0
{
delta *= -2
MouseMove, 0, %delta%, 0, R
MouseGetPos, x, oldy
}
return

What could I change in the script in order to make it work?
greetz, Frans
Back to top
Murp|e



Joined: 12 Jan 2007
Posts: 240
Location: Norway

PostPosted: Mon May 21, 2007 12:05 am    Post subject: Reply with quote

I'm afraid I can't help you, but I tried to google around a bit and found someone who was in the exact same situation as you:
http://answers.google.com/answers/threadview?id=408579

Since the script you pasted doesn't work in your game, I'm not sure any AutoHotkey scripts will??
Back to top
View user's profile Send private message Visit poster's website
frans
Guest





PostPosted: Mon May 21, 2007 1:49 am    Post subject: Reply with quote

The problem is that It doesn't work at al...I don't want to use it in a gaming environment, just in windows.. But thanks for your reply anyway!
Back to top
Laszlo



Joined: 14 Feb 2005
Posts: 4016
Location: Pittsburgh

PostPosted: Mon May 21, 2007 2:19 am    Post subject: Reply with quote

This should invert the y (vertical) direction of the mouse:
Code:
BlockInput Mouse
SetMouseDelay -1

MouseGetPos x, oldy
SetTimer WatchMouse, 1
Return

WatchMouse:
   MouseGetPos x, y
   MouseMove 0, 2*(oldy-y), 0, R
   MouseGetPos x, oldy
Return

!z::ExitApp

This version inverts both axes
Code:
BlockInput Mouse
SetMouseDelay -1

MouseGetPos x0, y0
SetTimer WatchMouse, 1
Return

WatchMouse:
   MouseGetPos x, y
   MouseMove 2*(x0-x), 2*(y0-y), 0, R
   MouseGetPos x0, y0
Return

!z::ExitApp
Back to top
View user's profile Send private message
Murp|e



Joined: 12 Jan 2007
Posts: 240
Location: Norway

PostPosted: Mon May 21, 2007 2:35 am    Post subject: Reply with quote

Nice work Laszlo, although it seemed a little bit bumpy, this worked like a charm for me. But do you think it will work in the game that was requested considering the other script did not?

P.S. Don't dive below the taskbar with this thing on! : )
Back to top
View user's profile Send private message Visit poster's website
Laszlo



Joined: 14 Feb 2005
Posts: 4016
Location: Pittsburgh

PostPosted: Mon May 21, 2007 2:44 am    Post subject: Reply with quote

These scripts fail at the screen edges, because you cannot move the mouse any more out, what was necessary to move the pointer away from the edge.

This kind of mouse movement manipulation is always jerky a bit, because of the processing time and the timer routine, which cannot be activated more often than every 10..16ms, the Windows timer resolution.
Back to top
View user's profile Send private message
Laszlo



Joined: 14 Feb 2005
Posts: 4016
Location: Pittsburgh

PostPosted: Mon May 21, 2007 3:27 am    Post subject: Reply with quote

Here is a version of the x/y script, which does not fail on the screen edges: it keeps the mouse pointer 1 pixel from the sides.
Code:
#NoEnv
SetBatchLines -1
Process Priority,,R

BlockInput Mouse        ; user mouse input is ignored during MouseMove
CoordMode Mouse, Screen ; absolute coordinates
SysGet m, Monitor       ; get the screen edges
mLeft += 1, mRight -= 2, mTop += 1, mBottom -= 2
SetMouseDelay -1        ; fastest action

MouseGetPos x0, y0      ; get initial mouse pointer location
SetTimer WatchMouse, 1  ; run the subroutine fast (10..16ms)
Return

WatchMouse:
   MouseGetPos x, y     ; get current mouse position
   x0 += 2*(x0-x), x0 := x0 < mLeft ? mLeft : (x0 > mRight  ? mRight  : x0)
   y0 += 2*(y0-y), y0 := y0 < mTop  ? mTop  : (y0 > mBottom ? mBottom : y0)
   MouseMove x0, y0, 0  ; set new position as old, for the next timer
Return

!z::ExitApp             ; stop the madness; make the script persistent
Back to top
View user's profile Send private message
Frans
Guest





PostPosted: Mon May 21, 2007 12:00 pm    Post subject: Reply with quote

THANK YOU ALL!

for helping me out, it works perfectly! I'm really interested in learning how to use Autohotkey now! Thanks again for the posts!

Greetz, Frans
Back to top
Guest






PostPosted: Tue May 29, 2007 5:09 am    Post subject: Reply with quote

Is there any way you could also post a script for just the y-axis that doesn't fail at the edges?
Back to top
Laszlo



Joined: 14 Feb 2005
Posts: 4016
Location: Pittsburgh

PostPosted: Tue May 29, 2007 3:09 pm    Post subject: Reply with quote

Code:
#NoEnv
SetBatchLines -1
Process Priority,,R

BlockInput Mouse        ; user mouse input is ignored during MouseMove
CoordMode Mouse, Screen ; absolute coordinates
SysGet m, Monitor       ; get the screen edges
mTop += 1, mBottom -= 2
SetMouseDelay -1        ; fastest action

MouseGetPos x0, y0      ; get initial mouse pointer location
SetTimer WatchMouse, 1  ; run the subroutine fast (10..16ms)
Return

WatchMouse:
   MouseGetPos x, y     ; get current mouse position
   y0 += 2*(y0-y), y0 := y0 < mTop  ? mTop  : (y0 > mBottom ? mBottom : y0)
   MouseMove x, y0, 0  ; set new position as old, for the next timer
Return

!z::ExitApp             ; stop the madness; make the script persistent
Back to top
View user's profile Send private message
Disable
Guest





PostPosted: Tue May 29, 2007 11:47 pm    Post subject: Reply with quote

Can you disable one of the axis?
Back to top
Laszlo



Joined: 14 Feb 2005
Posts: 4016
Location: Pittsburgh

PostPosted: Tue May 29, 2007 11:51 pm    Post subject: Reply with quote

Code:
#NoEnv
SetBatchLines -1
Process Priority,,R

BlockInput Mouse        ; user mouse input is ignored during MouseMove
CoordMode Mouse, Screen ; absolute coordinates
SysGet m, Monitor       ; get the screen edges
mTop += 1, mBottom -= 2
SetMouseDelay -1        ; fastest action

MouseGetPos x0, y0      ; get initial mouse pointer location
SetTimer WatchMouse, 1  ; run the subroutine fast (10..16ms)
Return

WatchMouse:
   MouseGetPos x, y     ; get current mouse position
   y0 += 2*(y0-y), y0 := y0 < mTop  ? mTop  : (y0 > mBottom ? mBottom : y0)
   MouseMove x0, y0, 0  ; set new position as old, for the next timer
Return

!z::ExitApp             ; stop the madness; make the script persistent
Back to top
View user's profile Send private message
Disable
Guest





PostPosted: Wed May 30, 2007 11:26 pm    Post subject: Reply with quote

When i add a hotkey (so while you are pressing it) it does not work?
Back to top
Laszlo



Joined: 14 Feb 2005
Posts: 4016
Location: Pittsburgh

PostPosted: Thu May 31, 2007 1:06 am    Post subject: Reply with quote

The hotkey should start/stop the timer WatchMouse (On/Off).
Back to top
View user's profile Send private message
Tester



Joined: 06 Jul 2006
Posts: 48
Location: Poland

PostPosted: Mon May 05, 2008 10:39 pm    Post subject: Reply with quote

Laszlo wrote:
Here is a version of the x/y script, which does not fail on the screen edges: it keeps the mouse pointer 1 pixel from the sides.
...


Unfortunately none of it didn't work with digitizer input on TabletPC.
any other ideas how to revert tablet stylus movement?
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Ask for Help All times are GMT
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group