Example #1
0
    def Setup(self, plugin, waitTime):
        """
        This will be called inside the thread at the beginning.
        """
        self.plugin = plugin
        self.waitTime = waitTime
        self.timer = Timer(0, self.OnTimeOut)
        self.lastEvent = None

        wc = WNDCLASS()
        wc.hInstance = GetModuleHandle(None)
        wc.lpszClassName = "HiddenMceMessageReceiver"
        wc.lpfnWndProc = WNDPROC(self.MyWndProc)
        if not RegisterClass(byref(wc)):
            raise WinError()
        self.hwnd = CreateWindowEx(0, wc.lpszClassName,
                                   "MCE Remote Message Receiver",
                                   WS_OVERLAPPEDWINDOW, CW_USEDEFAULT,
                                   CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
                                   0, 0, wc.hInstance, None)
        if not self.hwnd:
            raise WinError()
        self.wc = wc
        self.hinst = wc.hInstance

        self.dll = WinDLL(os.path.join(PLUGIN_DIR, "MceIr.dll"))
        if not self.dll.MceIrRegisterEvents(self.hwnd):
            raise self.plugin.Exceptions.DeviceNotFound
        self.dll.MceIrSetRepeatTimes(1, 1)
    def Setup(self, plugin, msgQueue):
        self.plugin = plugin
        self.msgQueue = msgQueue

        self.wndClass = WNDCLASS(
            lpfnWndProc = WNDPROC(self.WindowProc),
            hInstance = GetModuleHandle(None),
            lpszClassName = "HiddenPCTVMessageReceiver"
        )
        if not RegisterClass(byref(self.wndClass)):
            raise WinError()

        self.hWnd = CreateWindow(
            self.wndClass.lpszClassName,
            self.wndClass.lpszClassName,
            WS_OVERLAPPEDWINDOW,
            CW_USEDEFAULT,
            CW_USEDEFAULT,
            CW_USEDEFAULT,
            CW_USEDEFAULT,
            None,
            None,
            self.wndClass.hInstance,
            None
        )
        if not self.hWnd:
            raise WinError()

        if not SetProp(self.hWnd, self.wndClass.lpszClassName, 658020):
            raise WinError()
Example #3
0
    def ScanDevices(self):
        nDevices = UINT(0)
        if -1 == GetRawInputDeviceList(None, byref(nDevices),
                                       sizeof(RAWINPUTDEVICELIST)):
            raise WinError()
        rawInputDeviceList = (RAWINPUTDEVICELIST * nDevices.value)()
        if -1 == GetRawInputDeviceList(
                cast(rawInputDeviceList, PRAWINPUTDEVICELIST), byref(nDevices),
                sizeof(RAWINPUTDEVICELIST)):
            raise WinError()

        cbSize = UINT()
        for i in range(nDevices.value):
            GetRawInputDeviceInfo(rawInputDeviceList[i].hDevice,
                                  RIDI_DEVICENAME, None, byref(cbSize))
            deviceName = create_unicode_buffer(cbSize.value)
            GetRawInputDeviceInfo(rawInputDeviceList[i].hDevice,
                                  RIDI_DEVICENAME, byref(deviceName),
                                  byref(cbSize))
            ridDeviceInfo = RID_DEVICE_INFO()
            cbSize.value = ridDeviceInfo.cbSize = sizeof(RID_DEVICE_INFO)
            GetRawInputDeviceInfo(rawInputDeviceList[i].hDevice,
                                  RIDI_DEVICEINFO, byref(ridDeviceInfo),
                                  byref(cbSize))
            if ridDeviceInfo.dwType != RIM_TYPEKEYBOARD:
                continue
            print "hDevice:", rawInputDeviceList[i].hDevice
            print "Type:", RIM_TYPES[rawInputDeviceList[i].dwType]
            print "DeviceName:", deviceName.value
            if ridDeviceInfo.dwType == RIM_TYPEHID:
                hid = ridDeviceInfo.hid
                print "dwVendorId: %04X" % hid.dwVendorId
                print "dwProductId: %04X" % hid.dwProductId
                print "dwVersionNumber: %04X" % hid.dwVersionNumber
                print "usUsagePage:", hid.usUsagePage
                print "usUsage:", hid.usUsage
            if ridDeviceInfo.dwType == RIM_TYPEKEYBOARD:
                kbd = ridDeviceInfo.keyboard
                print "dwType:", kbd.dwType
                print "dwSubType:", kbd.dwSubType
                print "dwKeyboardMode:", kbd.dwKeyboardMode
                print "dwNumberOfFunctionKeys:", kbd.dwNumberOfFunctionKeys
                print "dwNumberOfIndicators:", kbd.dwNumberOfIndicators
                print "dwNumberOfKeysTotal:", kbd.dwNumberOfKeysTotal
            if ridDeviceInfo.dwType == RIM_TYPEMOUSE:
                mouse = ridDeviceInfo.mouse
                print "dwId:", mouse.dwId
                print "dwNumberOfButtons:", mouse.dwNumberOfButtons
                print "dwSampleRate:", mouse.dwSampleRate
                print "fHasHorizontalWheel:", mouse.fHasHorizontalWheel
            print
    def Finish(self):
        if not RemoveProp(self.hWnd, self.wndClass.lpszClassName):
            raise WinError()

        if not DestroyWindow(self.hWnd):
            raise WinError()

        if not (
            UnregisterClass(
                self.wndClass.lpszClassName,
                self.wndClass.hInstance
            )
        ):
            raise WinError()
Example #5
0
 def Finish(self):
     """
     Overrides eg.ThreadWorker.Finish to destroy the window instance.
     """
     if not DestroyWindow(self.hwnd):
         raise WinError()
     self.hwnd = None
Example #6
0
 def Stop(self):
     self.messageProcs.clear()
     eg.ThreadWorker.Stop(self, 5.0)
     if not UnregisterClass(
         cast(self.classAtom, LPCTSTR),
         GetModuleHandle(None)
     ):
         raise WinError()
Example #7
0
 def Setup(self):
     """
     Overrides eg.ThreadWorker.Setup to create the window instance.
     """
     self.hwnd = CreateWindowEx(0, self.wndclass.lpszClassName,
                                self.windowName, WS_OVERLAPPEDWINDOW,
                                CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
                                CW_USEDEFAULT, 0, 0,
                                self.wndclass.hInstance, None)
     if not self.hwnd:
         raise WinError()
Example #8
0
 def __init__(self, windowName):
     self.windowName = windowName
     self.messageProcs = {
         WM_SIZE: [self.WmSizeHandler],
     }
     eg.ThreadWorker.__init__(self)
     wndclass = WNDCLASS(
         lpfnWndProc=WNDPROC(self.WindowProc),
         hInstance=GetModuleHandle(None),
         lpszMenuName=None,
         lpszClassName=self.windowName + "MessageReceiver",
     )
     self.classAtom = RegisterClass(byref(wndclass))
     if not self.classAtom:
         raise WinError()
     self.wndclass = wndclass
     self.hwnd = None
     self.nextWmUserMsg = WM_USER + 1000
     self.wmUserHandlers = {}
     self.freeWmUserMsgs = []
Example #9
0
    def Setup(  self,
                plugin,
                waitTime,
                pollTime,
                useDefaultPollTime,
                initTime = 15.0,
                checkRepeatFlag = False,
                repeatReleaseTime = 200 ):
        """
        This will be called inside the thread at the beginning.
        """
        self.lock = Lock()
        self.abort = False

        self.plugin = plugin
        self.waitTime = float(waitTime)/1000.0
        self.repeatReleaseTime = float(repeatReleaseTime)/1000.0
        self.pollTime = pollTime
        self.useDefaultPollTime = useDefaultPollTime
        self.defaultPollTime = -1

        self.LastKeyCode = -1

        self.checkRepeatFlag = checkRepeatFlag

        self.repeatCode = c_int(0)
        self.systemCode = c_int(0)
        self.keyCode    = c_int(0)

        self.lastEvent = eg.EventGhostEvent()
        self.keyStillPressed = False
        self.initTerminated = False

        self.timerInit = None
        self.timerKey = None

        self.hwnd = None
        self.dll  = None

        # load irremote.dll

        try:
            regHandle = _winreg.OpenKey(
                           _winreg.HKEY_LOCAL_MACHINE,
                           'SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Hauppauge WinTV Infrared Remote',
                           0,
                           _winreg.KEY_READ
                        )

            InstallString = _winreg.QueryValueEx(regHandle, 'UninstallString')[0]

            _winreg.CloseKey( regHandle )

            irremoteDir = InstallString.partition(' ')[0].rsplit('\\',1)[0]

            dllPath = os.path.join(irremoteDir, "irremote.DLL")


            self.dll = windll.LoadLibrary(dllPath)
            self.dll = WinDLL(dllPath)

        except:
            plugin.PrintError("Couldn't find irremote.dll! Reinstalling the Hauppauge "
                   "WinTV Infrared Remote package can solve the problem."
                  )
            raise self.plugin.Exceptions.DeviceNotFound

        self.IR_Open             = WINFUNCTYPE( c_int, HWND, c_int, c_byte, c_int )
        self.IR_Close            = WINFUNCTYPE( c_int, HWND, c_int )
        self.IR_GetSystemKeyCode = WINFUNCTYPE( c_int, POINTER( c_int), POINTER( c_int), POINTER( c_int) )
        self.TIMERPROC           = WINFUNCTYPE( None, HWND, c_uint, c_uint, DWORD )

        self.IR_Open             = self.dll.IR_Open
        self.IR_Close            = self.dll.IR_Close
        self.IR_GetSystemKeyCode = self.dll.IR_GetSystemKeyCode

        wc = WNDCLASS()
        wc.hInstance = GetDesktopWindow()
        wc.lpszClassName = "HaupPluginEventSinkWndClass"
        wc.lpfnWndProc = WNDPROC(self.MyWndProc)
        if not RegisterClass(byref(wc)):
            raise WinError()
        self.hwnd = CreateWindow(
            wc.lpszClassName,
            "HaupaugePlugin Event Window",
            WS_OVERLAPPEDWINDOW,
            CW_USEDEFAULT,
            CW_USEDEFAULT,
            CW_USEDEFAULT,
            CW_USEDEFAULT,
            0,
            0,
            wc.hInstance,
            None
        )
        if not self.hwnd:
            raise WinError()
        self.wc = wc
        self.hinst = wc.hInstance

        self.timerInit = Timer( initTime, self.PostInit)        # Init delayed init timer ( in case of standby problems)
        self.timerInit.start()