def CreatePowerClass(lParam, cls): powerBroadcast = cast(lParam, POINTER(cls)) powerSetting = powerBroadcast.contents.PowerSetting data = powerBroadcast.contents.Data msgs = POWER_MESSAGES.get(powerSetting, None) if msgs is not None: return msgs.get(data, None)
def OnCopyData(self, hwnd, mesg, wParam, lParam): copyData = cast(lParam, PCOPYDATASTRUCT) hEvent = cast(copyData.contents.lpData, POINTER(HEVENT)) if not ( copyData.contents.dwData == 0 and copyData.contents.cbData == sizeof(HEVENT) and hEvent.contents.dwHookType == WH_KEYBOARD ): eg.eventThread.Call(eg.Print, "return") return mTime = time.clock() msg = MSG() while PeekMessage(byref(msg), 0, WM_INPUT, WM_INPUT, PM_REMOVE): self.OnRawInput(0, msg.message, msg.wParam, msg.lParam) vKey = hEvent.contents.wParam repeatCount = hEvent.contents.lParam & 0xFFFF keyState = (hEvent.contents.lParam >> 30) & 0x01 extended = (hEvent.contents.lParam >> 24) & 0x01 if (hEvent.contents.lParam >> 31) & 0x01: transition = "KEYUP" state = False else: transition = "KEYDOWN" state = True info = "%f Hook %s: %s(%d), keyState=%d, extended=%d" % ( mTime, transition, VK_KEYS[vKey], hEvent.contents.wParam, keyState, extended, ) if GetAsyncKeyState(162): #LCtrl info += "LCtrl " if GetAsyncKeyState(163): #RCtrl info += "RCtrl " i = 0 while i < len(self.buf): rawKeyboardData = self.buf[i] if rawKeyboardData.tick < time.clock() - 0.2: eg.eventThread.Call(eg.Print, "*** removed to old message") del self.buf[i] continue if ( rawKeyboardData.vKey == vKey and rawKeyboardData.state == state ): del self.buf[i] # if rawKeyboardData.device != 65603: # eg.eventThread.Call(eg.Print, "blocked") # return 1 eg.eventThread.Call(eg.Print, info) return 0 i += 1 eg.eventThread.Call(eg.Print, "not found")
def __start__(self): self.dll = None self.handles = [] self.contexts = [] # Try opening DLL paths = [ os.path.join(os.path.abspath(os.environ["ProgramFiles"]), "TT-Viewer"), os.path.abspath(os.path.dirname(__file__)), ] dll = None for path in paths: try: dll = cdll.LoadLibrary(os.path.join(path, "ttBdaDrvApi_Dll.dll")) dll.bdaapiEnumerate.restype = c_uint dll.bdaapiOpen.restype = POINTER(c_int) dll.bdaapiClose.restype = None break except WindowsError: dll = None if dll is None: self.PrintError( "Couldn't find ttBdaDrvApi_Dll.dll!\n" "Install the TT-Viewer application in %s\n" "or place the dll in %s." % (paths[0], paths[1]) ) raise self.Exceptions.DeviceNotFound self.dll = dll self.cCallback = IRCALLBACKFUNC(self.IrCallback) context = 0 for type in range(len(DEVICE_TYPES)): for index in range(self.dll.bdaapiEnumerate(type)): handle = dll.bdaapiOpen(type, index) if handle.contents != 0 and handle.contents != -1: error = dll.bdaapiOpenIR(handle, self.cCallback, context) context += 1 if (error == 0): #print "Listening to device %s(%d)" % (DEVICE_TYPES[type], index) self.handles.append(handle) else: self.dll.bdaapiClose(handle) if len(self.handles) == 0: raise self.Exceptions.DeviceNotFound self.timer = eg.ResettableTimer(self.OnTimeout) self.event = None self.lastKey = None
def OnRawInput(self, hwnd, mesg, wParam, lParam): pcbSize = UINT() GetRawInputData( lParam, RID_INPUT, None, byref(pcbSize), sizeof(RAWINPUTHEADER) ) buf = create_string_buffer(pcbSize.value) GetRawInputData( lParam, RID_INPUT, buf, byref(pcbSize), sizeof(RAWINPUTHEADER) ) pRawInput = cast(buf, POINTER(RAWINPUT)) keyboard = pRawInput.contents.data.keyboard if keyboard.VKey == 0xFF: eg.eventThread.Call(eg.Print, "0xFF") return 0 #print "Scan code:", keyboard.MakeCode info = "" mTime = time.clock() if keyboard.Message == WM_KEYDOWN: transition = "KEYDOWN" elif keyboard.Message == WM_KEYUP: transition = "KEYUP" else: transition = " %d" % keyboard.Message info = "%f " % mTime info += "RawI %s: %s(%d), " % ( transition, VK_KEYS[keyboard.VKey], keyboard.VKey ) if GetAsyncKeyState(162): #LCtrl info += "LCtrl " if GetAsyncKeyState(163): #RCtrl info += "RCtrl " info += "Scan: %d, " % keyboard.MakeCode info += "Extra: %d, " % keyboard.ExtraInformation info += "Device: %r, " % pRawInput.contents.header.hDevice #print "Flags:", keyboard.Flags rawKeyboardData = RawKeyboardData( keyboard.VKey, pRawInput.contents.header.hDevice, keyboard.Message in (WM_KEYDOWN, WM_SYSKEYDOWN), time.clock() ) self.buf.append(rawKeyboardData) eg.eventThread.Call(eg.Print, info) if GET_RAWINPUT_CODE_WPARAM(wParam) == RIM_INPUT: return DefWindowProc(hwnd, mesg, wParam, lParam) return 0
# # EventGhost is distributed in the hope that it will be useful, but WITHOUT # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for # more details. # # You should have received a copy of the GNU General Public License along # with EventGhost. If not, see <http://www.gnu.org/licenses/>. from os.path import join # Local imports import eg from eg.WinApi.Dynamic import c_ubyte, cast, POINTER, WinDLL PUBYTE = POINTER(c_ubyte) class WinUsbRemote(object): threadId = None dll = None def __init__(self, deviceInterfaceGuid, callback, dataSize=1, suppressRepeat=False): self.callback = callback self.dataSize = dataSize self.suppressRepeat = suppressRepeat self.deviceInterfaceGuid = unicode(deviceInterfaceGuid)
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()
0x57: "Blue", 0x7A: "Record", 0x7B: "Play", 0x7C: "Stop", 0x52: "Info", 0x7D: "Rewind", 0x7E: "Pause", 0x7F: "Forward", 0x62: "Guide", } DEVICE_TYPES = [ "Unknown", "Budget 2", "Budget 3", "USB 2", "USB 2 Pinnacle", "USB 2 DSS" ] IRCALLBACKFUNC = CFUNCTYPE(None, c_int, POINTER(c_uint)) class TTIRBDA(eg.PluginBase): def __init__(self): pass def __close__(self): pass def __start__(self): self.dll = None self.handles = [] self.contexts = [] # Try opening DLL
from eg.WinApi.Dynamic import (cdll, DWORD, POINTER, ULONG, HANDLE, BYTE, c_void_p, c_int, CFUNCTYPE, CDLL) USBIR_MODE_DIV = 2 # typedef void (*PIRCBFCN) (PVOID Context, # PVOID Buf, # ULONG len, // buffer length in bytes # USBIR_MODES IRMode, # HANDLE hOpen, # BYTE DevIdx); IRCALLBACKFUNC = CFUNCTYPE( c_void_p, # return type c_void_p, # Context POINTER(DWORD), # Buf ULONG, # len (buffer length in bytes) c_int, # IRMode (of enum USBIR_MODES) HANDLE, # hOpen BYTE # DevIdx ) class TTIR(eg.IrDecoderPlugin): def __init__(self): eg.IrDecoderPlugin.__init__(self, 1) def __close__(self): self.irDecoder.Close() def __start__(self):