WorldViz User Forum  

Go Back   WorldViz User Forum > Vizard

Thread Tools Rate Thread Display Modes
Old 02-25-2016, 09:21 AM
Seadna Seadna is offline
Join Date: Nov 2015
Posts: 40
Question Joystick controlled virtual mouse

Hi folks,

I have been working on code to control the canvas mouse cursor using a joystick. Below is the code i have come up with. The issues i'm having are that I cannot figure out how to bind the mouse click to a button on the joystick. Also i'm sure my beginners code needs tidying up but i cannot figure out where. For some reason when making a 'psoitive' movement (i.e. x+ and y+) the cursor movement seems to jump a little and is not smooth however in reverse when move towarsd 0,0 on the canvas it works perfectly smooth. I cannot see what i need to change in my code. Can hear my brain sizzling at this stage!!

Any help is super appreciated!

jx = 0.000
jy = 0.000
def UpdateJoystickMovement():
                e = viz.elapsed()
                x,y,z = joystick.getPosition()
                print 'Cursor is at ' + str(canvas.getCursorPosition())
                print 'XY: ' + str(x) + '-' + str(y)
                global jx
                global jy
                if x > 0:
                                if x < jx:
                                                jx = jx
                                                jx = (x+jx/1000)
                elif x < 0:
                                if x > jx:
                                                jx = jx
                                                jx = (jx+x/1000)
                if y > 0:
                                if y < jy:
                                                jy = jy
                                                jy = (y+jy/1000)
                elif y < 0:
                                if y > jy:
                                                jy = jy
                                                jy = (jy+y/1000)

vizact.ontimer(0, UpdateJoystickMovement)
Reply With Quote
Old 02-25-2016, 09:25 AM
Seadna Seadna is offline
Join Date: Nov 2015
Posts: 40
I figured the smoothness issue out less than a minute after original post!

I needed to change jx = (x+jx/1000) to jx = (jx+x/1000)

Had been looking at it for hours and didnt see it! I'm still not sure how to replicate the mouse click however.
Reply With Quote
Old 02-26-2016, 02:56 AM
Seadna Seadna is offline
Join Date: Nov 2015
Posts: 40
I have tried using pyautogui library for the left-click but it does not work when the mouse is captured in the canvas. I get an error 'Specified procedure could not be found'

I'm going to look up if there is another way maybe using windows API's, hopefully it is not too complicated to implement.
Reply With Quote
Old 02-26-2016, 03:29 AM
Seadna Seadna is offline
Join Date: Nov 2015
Posts: 40
I eventually found the .sendMouseButtonEvent don't know why it took me so long to find it in the help file!
Reply With Quote
Old 02-29-2016, 03:18 PM
JasmineJasmine JasmineJasmine is offline
Join Date: Feb 2016
Posts: 6
I don't believe that you are making the right interface decisions if you require a joystick controlled by the mouse. If you are porting a mobile game to PC redesigning the interface to match the Keyboard/Mouse paradigm will be a better overall experience for the player. If you could give us more information as to what this Joystick is controlling that would help a lot as well.
Reply With Quote

canvas, click, cursor, joystick

Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
joystick position nmohandes Vizard 2 01-16-2012 10:03 AM
Mouse bug in V3 and V4 Renato Lima Vizard 2 05-11-2011 06:38 PM
Mouse event: how to detect no mouse move event, how to set mouse position? Zhi Vizard 3 04-11-2011 06:25 PM
how to remove velocity when mouse is disabled? jvacare1 Vizard 2 02-18-2010 10:25 AM
Navigating an avatar using mouse position(2D) in 3D environment james007 Vizard 1 10-16-2009 11:29 AM

All times are GMT -7. The time now is 03:15 PM.

Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Copyright 2002-2023 WorldViz LLC