forked from tidzo/pyvjoy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
vjoydevice.py
executable file
·77 lines (49 loc) · 1.95 KB
/
vjoydevice.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
from pyvjoy.constants import *
from pyvjoy.exceptions import *
import pyvjoy._sdk as _sdk
class VJoyDevice(object):
"""Object-oriented API for a vJoy Device"""
def __init__(self,rID=None, data=None):
"""Constructor"""
self.rID=rID
self._sdk=_sdk
self._vj=self._sdk._vj
if data:
self.data = data
else:
#TODO maybe - have self.data as a wrapper object containing the Struct
self.data = self._sdk.CreateDataStructure(self.rID)
try:
_sdk.vJoyEnabled()
_sdk.AcquireVJD(rID)
#TODO FIXME
except vJoyException:
raise
def set_button(self,buttonID,state):
"""Set a given button (numbered from 1) to On (1 or True) or Off (0 or False)"""
return self._sdk.SetBtn(state,self.rID,buttonID)
def set_axis(self,AxisID, AxisValue):
"""Set a given Axis (one of pyvjoy.HID_USAGE_X etc) to a value (0x0000 - 0x8000)"""
return self._sdk.SetAxis(AxisValue,self.rID,AxisID)
def set_disc_pov(self, PovID, PovValue):
return self._sdk.SetDiscPov(PovValue, self.rID, PovID)
def set_cont_pov(self, PovID, PovValue):
return self._sdk.SetContPov(PovValue, self.rID, PovID)
def reset(self):
"""Reset all axes and buttons to default values"""
return self._sdk.ResetVJD(self.rID)
def reset_data(self):
"""Reset the data Struct to default (does not change vJoy device at all directly)"""
self.data=self._sdk.CreateDataStructure(self.rID)
def reset_buttons(self):
"""Reset all buttons on the vJoy Device to default"""
return self._sdk.ResetButtons(self.rID)
def reset_povs(self):
"""Reset all Povs on the vJoy Device to default"""
return self._sdk.ResetPovs(self.rID)
def update(self):
"""Send the stored Joystick data to the device in one go (the 'efficient' method)"""
return self._sdk.UpdateVJD(self.rID, self.data)
def __del__(self):
# free up the controller before losing access
self._sdk.RelinquishVJD(self.rID)