control mouse with joystick windows

1

I try to control my mouses absolute position with a stay-put, two-axis joystick. I want this running on a windows 7. I already tried many different programs as

  • jmouse
  • Xpadder
  • Joymouse
  • joy 2 mouse

joy 2 mouse works best for me so far, as I can control the x- and y-axis with the absolute position of the joystick, but i came across 2 problems

  1. the mouse stutters sometimes, even when I am not moving the joystick
  2. I can only set the "up-y-axis" and the "down-y-axis", so that there is a small angle around the root position of the joystick, where no mouse movement is applied.

For me it would also work, if someone knows a reliable way to get just the exact position of this joystick (on win7), then I can set the mouse position myself.

The imprecision of the joystick is caused by the software. I got the same hardware working properly on my mac.

Milla Well

Posted 2012-10-30T12:42:36.757

Reputation: 271

Answers

1

I found a solution myself by handling the joystick events and mouse position with python, pygame and win32api

import pygame, sys,os
import win32api, win32con
from win32api import GetSystemMetrics
from pygame.locals import * 

width = GetSystemMetrics (0)
height = GetSystemMetrics (1)

pygame.init() 
pygame.joystick.init()
joystick = pygame.joystick.Joystick(0)
joystick = joystick.init()
while 1: 
    for event in pygame.event.get(): 
          if event.type == QUIT: 
             sys.exit(0) 
          else: 
            if event.type == 7:
                if event.axis==0:
                    a = (event.value + 1)/2
                    x,y = win32api.GetCursorPos()
                    win32api.SetCursorPos((x,int(a*height)))
                elif event.axis==2:
                    a = (event.value + 1)/2
                    x, y = win32api.GetCursorPos()
                    win32api.SetCursorPos((int(a*width),y))

This might not be a solution for everyone, because it is to be compiled and all dependencies need to be included. But in this way, it is possible to control all mouse events very precise. It is a small code snippet and pretty straightforward. It is based on the simple pygame event loop.

Milla Well

Posted 2012-10-30T12:42:36.757

Reputation: 271