2010-03-31 00:24:16 +02:00
|
|
|
#!/usr/bin/env python
|
|
|
|
|
|
|
|
from ctypes import *
|
|
|
|
import platform
|
|
|
|
from mmlmouse import Mouse
|
2010-04-02 11:36:47 +02:00
|
|
|
from time import sleep
|
2010-03-31 00:24:16 +02:00
|
|
|
|
|
|
|
class MMLCoreException(Exception):
|
|
|
|
def __init__(self, err):
|
|
|
|
Exception.__init__(self, err)
|
|
|
|
|
|
|
|
class MMLCore(object):
|
2010-04-15 00:13:31 +02:00
|
|
|
'''
|
|
|
|
The MMLCore object is to be opened only once per Python instance.
|
|
|
|
It opens the libmml library, and calls init().
|
|
|
|
'''
|
2010-03-31 00:24:16 +02:00
|
|
|
def __init__(self, dllpath):
|
|
|
|
self.dll = CDLL(dllpath)
|
|
|
|
|
|
|
|
self.dll.init.restype = c_int
|
|
|
|
self.dll.init.argtypes = None
|
|
|
|
if self.dll.init() != 0:
|
|
|
|
del self.dll
|
|
|
|
raise MMLCoreException("Could not initialize the DLL")
|
|
|
|
|
|
|
|
def __del__(self):
|
|
|
|
del self.dll
|
|
|
|
|
|
|
|
DLL = MMLCore('../libmml.so')
|
|
|
|
|
|
|
|
m = Mouse(DLL)
|
2010-04-02 01:48:06 +02:00
|
|
|
|
|
|
|
|
2010-04-02 11:36:47 +02:00
|
|
|
print m[(Mouse.Pos, Mouse.Left, Mouse.Right)]
|
|
|
|
m[(Mouse.Pos, Mouse.Right)] = ((300,300), True)
|
|
|
|
print m.getButtonStates()
|
2010-04-02 01:48:06 +02:00
|
|
|
|
2010-04-02 11:36:47 +02:00
|
|
|
sleep(2)
|
2010-04-02 01:48:06 +02:00
|
|
|
|
2010-04-02 11:36:47 +02:00
|
|
|
# Reset all buttons..
|
|
|
|
m[(Mouse.Left, Mouse.Right, Mouse.Middle)] = [False for x in range(3)]
|
2010-04-02 01:48:06 +02:00
|
|
|
for v in zip((Mouse.Left, Mouse.Right), m[(Mouse.Left, Mouse.Right)]):
|
|
|
|
print v
|
2010-04-02 11:36:47 +02:00
|
|
|
print m.getPos()
|
2010-04-02 01:48:06 +02:00
|
|
|
|
2010-03-31 00:24:16 +02:00
|
|
|
|
|
|
|
del DLL
|
|
|
|
|
|
|
|
|