Menu

Mouse to Joystick Conversion

Help
Ron Cortex
2010-08-20
2013-04-23
  • Ron Cortex

    Ron Cortex - 2010-08-20

    Hi everyone,

    Okay, I've been sifting through the forums and API Docs, and I have yet to find a way to create a joystick event using Gizmo Daemon.  …so, before spending hours of more time on trying to figure it out, is there actually a way to create a joystick (button or axis) event with Gizmo Daemon?

    Specifically, I am trying to write a script that will allow me to use my mouse as a joystick (for a particular game I have a knack for ^_^").  I do see the Joystick button codes (GizmoKey.BTN_TRIGGER, etc.) but I don't see anything for joystick axes.  Is it just me, or simulating joystick events is not fully implemented in Gizmo Daemon?

    Anywhos, any help would be appreciated.  Oh, and here is the code I have so far, in case your interested…

    ############################
    # Imports
    ##########################

    from GizmoDaemon import *
    from GizmoScriptDefault import *
    import subprocess

    ENABLED = True
    VERSION_NEEDED = 3.2
    INTERESTED_CLASSES =

    ############################
    # MouseConvertToJoystick Class definition
    ##########################

    class MouseConvertToJoystick(GizmoScriptDefault):

    ############################
    # Public Functions
    ##########################

    def onDeviceEvent(self, Event, Gizmo = None):
    '''"
                    Replace <JOYSTICK_METHOD> and <JOY_AXIS> with appropriate calls…and then tell me, please.  ^_^"
                    """
       if Event.Code == GizmoKey.BTN_LEFT:
    Gizmod.<JOYSTICK_METHOD>.createEventRaw(GizmoEventType.EV_KEY, GizmoKey.BTN_TRIGGER, Event.Value)
    print Gizmod.Mice
    return True
       elif Event.Code == GizmoKey.BTN_RIGHT:
       Gizmod.<JOYSTICK_METHOD>.createEventRaw(GizmoEventType.EV_ABS, GizmoKey.BTN_TOP, Event.Value)
       return True
       elif Event.Code == GizmoKey.BTN_MIDDLE:
       Gizmod.<JOYSTICK_METHOD>.createEventRaw(GizmoEventType.EV_ABS, GizmoKey.BTN_THUMB2, Event.Value)
       return True
       elif Event.Code == GizmoKey.BTN_SIDE:
       Gizmod.<JOYSTICK_METHOD>.createEventRaw(GizmoEventType.EV_ABS, GizmoKey.BTN_TOP2, Event.Value)
       return True
       elif Event.Code == GizmoKey.BTN_EXTRA:
       Gizmod.<JOYSTICK_METHOD>.createEventRaw(GizmoEventType.EV_ABS, GizmoKey.BTN_PINKIE, Event.Value)
       return True
       elif Event.Code == GizmoKey.BTN_TASK:
       Gizmod.<JOYSTICK_METHOD>.createEventRaw(GizmoEventType.EV_ABS, GizmoKey.BTN_THUMB, Event.Value)
       return True
       elif Event.Code == GizmoMouseAxis.WHEEL:
       Gizmod.<JOYSTICK_METHOD>.createEventRaw(GizmoEventType.EV_ABS, <JOY_AXIS>.Z, Event.Value)
       return True
       elif Event.Code == GizmoMouseAxis.Y:
       Gizmod.<JOYSTICK_METHOD>.createEventRaw(GizmoEventType.EV_REL, <JOY_AXIS>.Y, Event.Value)
       return True
       elif Event.Code == GizmoMouseAxis.X:
       Gizmod.<JOYSTICK_METHOD>.createEventRaw(GizmoEventType.EV_REL, <JOY_AXIS>.X, Event.Value)
       return True
       else:
    return False

    ############################
    # Private Functions
    ##########################

    def __init__(self):
    GizmoScriptDefault.__init__(self, ENABLED, VERSION_NEEDED, INTERESTED_CLASSES)

    ############################
    # MouseConvertToJoystick class end
    ##########################

    MouseConvertToJoystick()

     
  • Ron Cortex

    Ron Cortex - 2010-08-20

    Sorry, guys.  My code had a crud-load of errors in it, primarily removing "Default Fancy Keyboard Event Mapping" comment, which actually prevented it from executing for some reason, amid some other embarrassing mixups.  Here's the updated code:

    #***
      #*********************************************************************
    #*************************************************************************
    #***
    #*** GizmoDaemon Config Script
    #*** Mouse ConvertToJoystick config
    #***
    #*****************************************
      #*****************************************
        #***

    ############################
    # Imports
    ##########################

    from GizmoDaemon import *
    from GizmoScriptDefault import *
    import subprocess

    ENABLED = True
    VERSION_NEEDED = 3.2
    INTERESTED_CLASSES =

    ############################
    # MouseConvertToJoystick Class definition
    ##########################

    class MouseConvertToJoystick(GizmoScriptDefault):
    """
    Default Fancy Keyboard Event Mapping
    """

    ############################
    # Public Functions
    ##########################

    def onDeviceEvent(self, Event, Gizmo = None):

    # process the key - Replace the <JOYSTICK_METHOD> and <JOY_AXIS> tags with the appropriate calls…  Thx!
       if Event.Code == GizmoKey.BTN_LEFT:
    Gizmod.<JOYSTICK_METHOD>.createEventRaw(GizmoEventType.EV_KEY, GizmoKey.BTN_TRIGGER, Event.Value)
    return True
       elif Event.Code == GizmoKey.BTN_RIGHT:
       Gizmod.<JOYSTICK_METHOD>.createEventRaw(GizmoEventType.EV_KEY, GizmoKey.BTN_TOP, Event.Value)
       return True
       elif Event.Code == GizmoKey.BTN_MIDDLE:
       Gizmod.<JOYSTICK_METHOD>.createEventRaw(GizmoEventType.EV_KEY, GizmoKey.BTN_THUMB2, Event.Value)
       return True
       elif Event.Code == GizmoKey.BTN_SIDE:
       Gizmod.<JOYSTICK_METHOD>.createEventRaw(GizmoEventType.EV_KEY, GizmoKey.BTN_TOP2, Event.Value)
       return True
       elif Event.Code == GizmoKey.BTN_EXTRA:
       Gizmod.<JOYSTICK_METHOD>.createEventRaw(GizmoEventType.EV_KEY, GizmoKey.BTN_PINKIE, Event.Value)
       return True
       elif Event.Code == GizmoKey.BTN_TASK:
       Gizmod.<JOYSTICK_METHOD>.createEventRaw(GizmoEventType.EV_KEY, GizmoKey.BTN_THUMB, Event.Value)
       return True
       elif Event.Code == <JOY_AXIS>.WHEEL:
    Gizmod.<JOYSTICK_METHOD>.createEventRaw(GizmoEventType.EV_ABS, <JOY_AXIS>.Z, Event.Value, Event.Value)
       return True
       elif Event.Code == <JOY_AXIS>.Y:
       Gizmod.<JOYSTICK_METHOD>.createEventRaw(GizmoEventType.EV_ABS, <JOY_AXIS>.Y, Event.Value, Event.Value)
       return True
       elif Event.Code == <JOY_AXIS>.X:
       Gizmod.<JOYSTICK_METHOD>.createEventRaw(GizmoEventType.EV_ABS, <JOY_AXIS>.X, Event.Value, Event.Value)
       return True
       else:
       # unmatched event, keep processing
    return False

    ############################
    # Private Functions
    ##########################

    def __init__(self):
    """
    Default Constructor
    """

    GizmoScriptDefault.__init__(self, ENABLED, VERSION_NEEDED, INTERESTED_CLASSES)

    ############################
    # MouseConvertToJoystick class end
    ##########################

    # register the user script
    MouseConvertToJoystick()

     

Log in to post a comment.