Ejemplo n.º 1
0
    def _checkForStateChange(self):
        g1=self._device_state.Gamepad
        g2=self._device_state_buffer.Gamepad
        changed={}

        if g1.wButtons!=g2.wButtons:
            buttonNameList=[]
            if g2.wButtons!=0:
                for k in XInputGamePadConstants._keys:
                    if g2.wButtons&k == k:
                        buttonNameList.append(XInputGamePadConstants._names[k])
            changed['Buttons']=buttonNameList


        if g1.bLeftTrigger!=g2.bLeftTrigger:
            changed['LeftTrigger']=g2.bLeftTrigger/255.0
        if g1.bRightTrigger!=g2.bRightTrigger:
            changed['RightTrigger']=g2.bRightTrigger/255.0


        if g1.sThumbLX!=g2.sThumbLX or g1.sThumbLY!=g2.sThumbLY:
            nl1=xinput.normalizeThumbStickValues(g1.sThumbLX,g1.sThumbLY,xinput.XINPUT_GAMEPAD_LEFT_THUMB_DEADZONE)
            nl2=xinput.normalizeThumbStickValues(g2.sThumbLX,g2.sThumbLY,xinput.XINPUT_GAMEPAD_LEFT_THUMB_DEADZONE)
            if (nl1 != nl2):
                changed['LeftThumbStick']=nl2
        if g1.sThumbRX!=g2.sThumbRX or g1.sThumbRY!=g2.sThumbRY:
            nr1=xinput.normalizeThumbStickValues(g1.sThumbRX,g1.sThumbRY,xinput.XINPUT_GAMEPAD_RIGHT_THUMB_DEADZONE)
            nr2=xinput.normalizeThumbStickValues(g2.sThumbRX,g2.sThumbRY,xinput.XINPUT_GAMEPAD_RIGHT_THUMB_DEADZONE)
            if (nr1 != nr2):
                changed['RightThumbStick']=nr2

        return changed
Ejemplo n.º 2
0
    def getThumbSticks(self, gamepad_state=None):
        """
        Returns a dictionary providing the state of the left and right thumbsticks on the gamepad.
        based on data from last GamepadStateChangeEvent read.
        The dictionary contains the following key:value pairs:

        * time : float. The sec.msecusec time when the thumbstick states being reported were read.
        * confidence_interval : float. The sec.msecusec difference between the device poll that contained the event data being used, and the previous device poll time. Therefore, it is possible that the device event time reported could have been between the time reported and reported time - confidence_interval.
        * left_stick: (x, y, magnitude). The state of the left thumbstick as a tuple of three float values, each with 12 bit resolution. x and y can range between -1.0 and 1.0, representing the position each dimension of the current thumbstick position (- values are leftward or downward, + values are rightward or upward). The magnitude can be between 0.0 and 1.0, representing the amount the thumbstick has been moved in the combined 2D movement space. 0.0 equals no movement, 1.0 equals the thumbstick being pushed fully to the edge of motion.
        * right_stick: (x, y, magnitude). The state of the right thumbstick as a tuple of three float values, each with 12 bit resolution. x and y can range between -1.0 and 1.0,  representing the position each dimension of the current thumbstick position (- values are leftward or downward, + values are rightward or upward). The magnitude can be between 0.0 and 1.0, representing the amount the thumbstick has been moved in the combined 2D movement space. 0.0 equals no movement, 1.0 equals the thumbstick being pushed fully to the edge of motion.

        Args:
            None

        Returns:
            dict: Thumbstick state information dict as described in the method doc.
        """
        if gamepad_state is None:
            gamepad_state = self._device_state.Gamepad
        leftStick = xinput.normalizeThumbStickValues(
            gamepad_state.sThumbLX,
            gamepad_state.sThumbLY,
            xinput.XINPUT_GAMEPAD_LEFT_THUMB_DEADZONE)
        rightStick = xinput.normalizeThumbStickValues(
            gamepad_state.sThumbRX,
            gamepad_state.sThumbRY,
            xinput.XINPUT_GAMEPAD_RIGHT_THUMB_DEADZONE)
        return dict(
            time=self._state_time,
            confidence_interval=self._time_ci,
            left_stick=leftStick,
            right_stick=rightStick)
    def getThumbSticks(self, gamepad_state=None):
        """
        Returns a dictionary providing the state of the left and right thumbsticks on the gamepad.
        based on data from last GamepadStateChangeEvent read. 
        The dictionary contains the following key:value pairs:
            
        * time : float. The sec.msecusec time when the thumbstick states being reported were read.
        * confidence_interval : float. The sec.msecusec difference between the device poll that contained the event data being used, and the previous device poll time. Therefore, it is possible that the device event time reported could have been between the time reported and reported time - confidence_interval.
        * left_stick: (x, y, magnitude). The state of the left thumbstick as a tuple of three float values, each with 12 bit resolution. x and y can range between -1.0 and 1.0, representing the position each dimention of the current thumbstick position (- values are leftward or downward, + values are rightward or upward). The magnitude can be between 0.0 and 1.0, representing the amount the thumbstick has been moved in the combined 2D movement space. 0.0 equals no movement, 1.0 equals the thumbstick being pushed fully to the edge of motion.
        * right_stick: (x, y, magnitude). The state of the right thumbstick as a tuple of three float values, each with 12 bit resolution. x and y can range between -1.0 and 1.0,  representing the position each dimention of the current thumbstick position (- values are leftward or downward, + values are rightward or upward). The magnitude can be between 0.0 and 1.0, representing the amount the thumbstick has been moved in the combined 2D movement space. 0.0 equals no movement, 1.0 equals the thumbstick being pushed fully to the edge of motion.
 
        Args:
            None
            
        Returns:
            dict: Thumbstick state information dict as described in the method doc.
        """
        if gamepad_state == None:
            gamepad_state = self._device_state.Gamepad
        leftStick = xinput.normalizeThumbStickValues(
            gamepad_state.sThumbLX, gamepad_state.sThumbLY,
            xinput.XINPUT_GAMEPAD_LEFT_THUMB_DEADZONE)
        rightStick = xinput.normalizeThumbStickValues(
            gamepad_state.sThumbRX, gamepad_state.sThumbRY,
            xinput.XINPUT_GAMEPAD_RIGHT_THUMB_DEADZONE)
        return dict(time=self._state_time,
                    confidence_interval=self._time_ci,
                    left_stick=leftStick,
                    right_stick=rightStick)
    def _checkForStateChange(self):
        g1 = self._device_state.Gamepad
        g2 = self._device_state_buffer.Gamepad
        changed = {}

        if g1.wButtons != g2.wButtons:
            buttonNameList = []
            if g2.wButtons != 0:
                for k in XInputGamePadConstants._keys:
                    if g2.wButtons & k == k:
                        buttonNameList.append(XInputGamePadConstants._names[k])
            changed['Buttons'] = buttonNameList

        if g1.bLeftTrigger != g2.bLeftTrigger:
            changed['LeftTrigger'] = g2.bLeftTrigger / 255.0
        if g1.bRightTrigger != g2.bRightTrigger:
            changed['RightTrigger'] = g2.bRightTrigger / 255.0

        if g1.sThumbLX != g2.sThumbLX or g1.sThumbLY != g2.sThumbLY:
            nl1 = xinput.normalizeThumbStickValues(
                g1.sThumbLX, g1.sThumbLY,
                xinput.XINPUT_GAMEPAD_LEFT_THUMB_DEADZONE)
            nl2 = xinput.normalizeThumbStickValues(
                g2.sThumbLX, g2.sThumbLY,
                xinput.XINPUT_GAMEPAD_LEFT_THUMB_DEADZONE)
            if (nl1 != nl2):
                changed['LeftThumbStick'] = nl2
        if g1.sThumbRX != g2.sThumbRX or g1.sThumbRY != g2.sThumbRY:
            nr1 = xinput.normalizeThumbStickValues(
                g1.sThumbRX, g1.sThumbRY,
                xinput.XINPUT_GAMEPAD_RIGHT_THUMB_DEADZONE)
            nr2 = xinput.normalizeThumbStickValues(
                g2.sThumbRX, g2.sThumbRY,
                xinput.XINPUT_GAMEPAD_RIGHT_THUMB_DEADZONE)
            if (nr1 != nr2):
                changed['RightThumbStick'] = nr2

        return changed
Ejemplo n.º 5
0
 def getThumbSticks(self,gamepad_state=None):
     if gamepad_state == None:
         gamepad_state=self._device_state.Gamepad
     leftStick=xinput.normalizeThumbStickValues(gamepad_state.sThumbLX,gamepad_state.sThumbLY,xinput.XINPUT_GAMEPAD_LEFT_THUMB_DEADZONE)
     rightStick=xinput.normalizeThumbStickValues(gamepad_state.sThumbRX,gamepad_state.sThumbRY,xinput.XINPUT_GAMEPAD_RIGHT_THUMB_DEADZONE)
     return dict(time=self._state_time, confidence_interval=self._time_ci,LeftStick=leftStick,RightStick=rightStick)