예제 #1
0
def device_exists(vjoy_id):
    """Returns whether or not a device exists.

    :param vjoy_id id of the vjoy device to check
    :return True if the device exists, False otherwise
    """
    state = VJoyInterface.GetVJDStatus(vjoy_id)
    return state not in [VJoyState.Missing.value, VJoyState.Unknown.value]
예제 #2
0
def device_exists(vjoy_id):
    """Returns whether or not a device exists.

    A device that exists may be acquired by a different process and thus not
    usable by Gremlin.

    :param vjoy_id id of the vjoy device to check
    :return True if the device exists, False otherwise
    """
    state = VJoyInterface.GetVJDStatus(vjoy_id)
    return state not in [VJoyState.Missing.value, VJoyState.Unknown.value]
예제 #3
0
def device_available(vjoy_id):
    """Returns whether or not a device is available, i.e. can be acquired.

    :param vjoy_id id of the vjoy device to check
    :return True if the device is available, False otherwise
    """
    dev_free = VJoyInterface.GetVJDStatus(vjoy_id) == VJoyState.Free.value
    dev_acquire = VJoyInterface.AcquireVJD(vjoy_id)
    VJoyInterface.RelinquishVJD(vjoy_id)

    return dev_free & dev_acquire
예제 #4
0
    def __init__(self, vjoy_id):
        """Creates a new object.

        :param vjoy_id id of the vJoy device to initialize.
        """
        self.vjoy_id = None

        if not VJoyInterface.vJoyEnabled():
            logging.getLogger("system").error("vJoy is not currently running")
            raise VJoyError("vJoy is not currently running")
        if VJoyInterface.GetvJoyVersion() != 0x218:
            logging.getLogger("system").error(
                "Running incompatible vJoy version, 2.1.8 required"
            )
            raise VJoyError("Running incompatible vJoy version, 2.1.8 required")
        elif VJoyInterface.GetVJDStatus(vjoy_id) != VJoyState.Free.value:
            logging.getLogger("system").error(
                "Requested vJoy device is not available - vid: {}".format(vjoy_id)
            )
            raise VJoyError(
                "Requested vJoy device is not available - vid: {}".format(vjoy_id)
            )
        elif not VJoyInterface.AcquireVJD(vjoy_id):
            logging.getLogger("system").error(
                "Failed to acquire the vJoy device - vid: {}".format(vjoy_id)
            )
            raise VJoyError(
                "Failed to acquire the vJoy device - vid: {}".format(vjoy_id)
            )

        self.vjoy_id = vjoy_id
        self.pid = os.getpid()

        # Initialize all controls
        self._axis_lookup = {}
        self._axis_names = {}
        self._axis = self._init_axes()
        self._button = self._init_buttons()
        self._hat = self._init_hats()

        # Timestamp of the last time the device was used
        self._last_active = time.time()
        self._keep_alive_timer = threading.Timer(
            VJoy.keep_alive_timeout,
            self._keep_alive
        )
        self._keep_alive_timer.start()

        # Reset all controls
        self.reset()