Esempio n. 1
0
 def __call__(self, imageFileName='', style=1):
     if imageFileName:
         image = wx.Image(imageFileName)
         imageFileName = eg.folderPath.RoamingAppData + '\\Microsoft\\Wallpaper1.bmp'
         image.SaveFile(imageFileName, wx.BITMAP_TYPE_BMP)
     tile, wstyle = (("0", "0"), ("1", "0"), ("0", "2"))[style]
     hKey = _winreg.CreateKey(
         _winreg.HKEY_CURRENT_USER,
         "Control Panel\\Desktop"
     )
     _winreg.SetValueEx(
         hKey,
         "TileWallpaper",
         0,
         _winreg.REG_SZ,
         tile
     )
     _winreg.SetValueEx(
         hKey,
         "WallpaperStyle",
         0,
         _winreg.REG_SZ,
         wstyle
     )
     _winreg.CloseKey(hKey)
     res = SystemParametersInfo(
         SPI_SETDESKWALLPAPER,
         0,
         create_unicode_buffer(imageFileName),
         SPIF_SENDCHANGE|SPIF_UPDATEINIFILE
     )
     if res == 0:
         self.PrintError(ctypes.FormatError())
Esempio n. 2
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
Esempio n. 3
0
def SetClipboardText(text):
    charBuffer = create_unicode_buffer(text)
    charBufferSize = sizeof(charBuffer)
    hGlobalMem = GlobalAlloc(GHND, charBufferSize)
    lpGlobalMem = GlobalLock(hGlobalMem)
    memcpy(lpGlobalMem, charBuffer, charBufferSize)
    GlobalUnlock(hGlobalMem)
    if not SafeOpenClipboard():
        return
    try:
        EmptyClipboard()
        SetClipboardData(CF_UNICODETEXT, hGlobalMem)
    finally:
        CloseClipboard()
Esempio n. 4
0
def SetClipboardText(text):
    charBuffer = create_unicode_buffer(text)
    charBufferSize = sizeof(charBuffer)
    hGlobalMem = GlobalAlloc(GHND, charBufferSize)
    lpGlobalMem = GlobalLock(hGlobalMem)
    memcpy(lpGlobalMem, charBuffer, charBufferSize)
    GlobalUnlock(hGlobalMem)
    if not SafeOpenClipboard():
        return
    try:
        EmptyClipboard()
        SetClipboardData(CF_UNICODETEXT, hGlobalMem)
    finally:
        CloseClipboard()
Esempio n. 5
0
 def __call__(
     self,
     pathname='',
     arguments='',
     winState=0,
     waitForCompletion=False,
     priority=2,
     workingDir=""
 ):
     returnValue = None
     pathname = eg.ParseString(pathname)
     if not workingDir:
         workingDir = dirname(abspath(pathname))
     arguments = eg.ParseString(arguments)
     commandLine = create_unicode_buffer('"%s" %s' % (pathname, arguments))
     startupInfo = STARTUPINFO()
     startupInfo.cb = sizeof(STARTUPINFO)
     startupInfo.dwFlags = STARTF_USESHOWWINDOW
     startupInfo.wShowWindow = WINSTATE_FLAGS[winState]
     priorityFlag = PRIORITY_FLAGS[priority]
     processInformation = PROCESS_INFORMATION()
     res = CreateProcess(
         None,              # lpApplicationName
         commandLine,       # lpCommandLine
         None,              # lpProcessAttributes
         None,              # lpThreadAttributes
         False,             # bInheritHandles
         priorityFlag|CREATE_NEW_CONSOLE, # dwCreationFlags
         None,              # lpEnvironment
         workingDir,        # lpCurrentDirectory
         startupInfo,       # lpStartupInfo
         processInformation # lpProcessInformation
     )
     if res == 0:
         raise self.Exception(FormatError())
     if waitForCompletion:
         WaitForSingleObject(processInformation.hProcess, INFINITE)
         exitCode = DWORD()
         if not GetExitCodeProcess(
             processInformation.hProcess,
             byref(exitCode)
         ):
             raise self.Exception(FormatError())
         returnValue = exitCode.value
     CloseHandle(processInformation.hProcess)
     CloseHandle(processInformation.hThread)
     return returnValue
Esempio n. 6
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
Esempio n. 7
0
    def __call__(
        self,
        pathname='',
        arguments='',
        winState=0,
        waitForCompletion=False,
        priority=2,
        workingDir="",
        triggerEvent=False,
        disableWOW64=False,
    ):
        returnValue = None
        pathname = eg.ParseString(pathname)
        if not workingDir:
            workingDir = dirname(abspath(pathname))
        arguments = eg.ParseString(arguments)
        commandLine = create_unicode_buffer('"%s" %s' % (pathname, arguments))
        startupInfo = STARTUPINFO()
        startupInfo.cb = sizeof(STARTUPINFO)
        startupInfo.dwFlags = STARTF_USESHOWWINDOW
        startupInfo.wShowWindow = WINSTATE_FLAGS[winState]
        priorityFlag = PRIORITY_FLAGS[priority]
        processInformation = self.processInformation = PROCESS_INFORMATION()
        disableWOW64 = disableWOW64 and IsWin64()
        if disableWOW64:
            prevVal = Wow64DisableWow64FsRedirection()
        res = CreateProcess(
            None,  # lpApplicationName
            commandLine,  # lpCommandLine
            None,  # lpProcessAttributes
            None,  # lpThreadAttributes
            False,  # bInheritHandles
            priorityFlag | CREATE_NEW_CONSOLE,  # dwCreationFlags
            None,  # lpEnvironment
            workingDir,  # lpCurrentDirectory
            startupInfo,  # lpStartupInfo
            processInformation  # lpProcessInformation
        )
        if disableWOW64:
            Wow64RevertWow64FsRedirection(prevVal)
        suffix = "%s.%s" % (self.text.eventSuffix, splitext(
            split(pathname)[1])[0])
        prefix = self.plugin.name.replace(' ', '')
        if res == 0:
            raise self.Exception(FormatError())
        if winState != 3 and PluginIsEnabled("Task"):

            def callback(dummyHwnd, dummyMesg, wParam, lParam):
                pids = GetPids(hwnd=lParam)
                pid = pids[0] if pids else False
                if pid == processInformation.dwProcessId:
                    try:
                        eg.messageReceiver.RemoveHandler(
                            WM_SHELLHOOKMESSAGE, refCallback)
                    except:
                        pass
                    sleep(0.3)  # Wait for windows to appear
                    hwnds = GetHwnds(pid=processInformation.dwProcessId)
                    if hwnds:
                        #print "Focused via GetHwnds"
                        for hwnd in hwnds:
                            if IsWindowVisible(hwnd):
                                BringHwndToFront(hwnd)
                                break
                    elif IsWindowVisible(lParam):
                        #print "Focused via ShellHook"
                        BringHwndToFront(lParam)
                elif not ProcessExists(processInformation.dwProcessId):
                    try:
                        eg.messageReceiver.RemoveHandler(
                            WM_SHELLHOOKMESSAGE, refCallback)
                    except:
                        pass
                    try:
                        eg.plugins.Window.FindWindow(basename(pathname))
                        if len(eg.lastFoundWindows):
                            #print "Focused via FindWindow"
                            BringHwndToFront(eg.lastFoundWindows[0])
                    except:
                        pass

            refCallback = callback
            WM_SHELLHOOKMESSAGE = RegisterWindowMessage("SHELLHOOK")
            eg.messageReceiver.AddHandler(WM_SHELLHOOKMESSAGE, callback)
        if waitForCompletion:
            WaitForSingleObject(processInformation.hProcess, INFINITE)
            exitCode = DWORD()
            if not GetExitCodeProcess(processInformation.hProcess,
                                      byref(exitCode)):
                raise self.Exception(FormatError())
            returnValue = exitCode.value
            if triggerEvent:
                eg.TriggerEvent(suffix, prefix=prefix)
            CloseHandle(processInformation.hProcess)
            CloseHandle(processInformation.hThread)
            return returnValue
        elif triggerEvent:
            te = self.TriggerEvent(processInformation, suffix, prefix)
            te.start()
        else:
            CloseHandle(processInformation.hProcess)
            CloseHandle(processInformation.hThread)
Esempio n. 8
0
 def __call__(
     self,
     pathname='',
     arguments='',
     winState=0,
     waitForCompletion=False,
     priority=2,
     workingDir="",
     triggerEvent=False,
     disableWOW64=False,
 ):
     returnValue = None
     pathname = eg.ParseString(pathname)
     if not workingDir:
         workingDir = dirname(abspath(pathname))
     arguments = eg.ParseString(arguments)
     commandLine = create_unicode_buffer('"%s" %s' % (pathname, arguments))
     startupInfo = STARTUPINFO()
     startupInfo.cb = sizeof(STARTUPINFO)
     startupInfo.dwFlags = STARTF_USESHOWWINDOW
     startupInfo.wShowWindow = WINSTATE_FLAGS[winState]
     priorityFlag = PRIORITY_FLAGS[priority]
     processInformation = self.processInformation = PROCESS_INFORMATION()
     disableWOW64 = disableWOW64 and IsWin64()
     if disableWOW64:
         prevVal = Wow64DisableWow64FsRedirection()
     res = CreateProcess(
         None,              # lpApplicationName
         commandLine,       # lpCommandLine
         None,              # lpProcessAttributes
         None,              # lpThreadAttributes
         False,             # bInheritHandles
         priorityFlag|CREATE_NEW_CONSOLE, # dwCreationFlags
         None,              # lpEnvironment
         workingDir,        # lpCurrentDirectory
         startupInfo,       # lpStartupInfo
         processInformation # lpProcessInformation
     )
     if disableWOW64:
         Wow64RevertWow64FsRedirection(prevVal)
     suffix = "%s.%s" % (
             self.text.eventSuffix,
             splitext(split(pathname)[1])[0]
         )
     prefix = self.plugin.name.replace(' ', '')
     if res == 0:
         raise self.Exception(FormatError())
     if winState != 3 and PluginIsEnabled("Task"):
         def callback(dummyHwnd, dummyMesg, wParam, lParam):
             pids = GetPids(hwnd = lParam)
             pid = pids[0] if pids else False
             if pid == processInformation.dwProcessId:
                 try:
                     eg.messageReceiver.RemoveHandler(WM_SHELLHOOKMESSAGE, refCallback)
                 except:
                     pass
                 sleep(0.3)  # Wait for windows to appear
                 hwnds = GetHwnds(pid = processInformation.dwProcessId)
                 if hwnds:
                     #print "Focused via GetHwnds"
                     for hwnd in hwnds:
                         if IsWindowVisible(hwnd):
                             BringHwndToFront(hwnd)
                             break
                 elif IsWindowVisible(lParam):
                     #print "Focused via ShellHook"
                     BringHwndToFront(lParam)
             elif not ProcessExists(processInformation.dwProcessId):
                 try:
                     eg.messageReceiver.RemoveHandler(WM_SHELLHOOKMESSAGE, refCallback)
                 except:
                     pass
                 try:
                     eg.plugins.Window.FindWindow(basename(pathname))
                     if len(eg.lastFoundWindows):
                         #print "Focused via FindWindow"
                         BringHwndToFront(eg.lastFoundWindows[0])
                 except:
                     pass
         refCallback = callback
         WM_SHELLHOOKMESSAGE = RegisterWindowMessage("SHELLHOOK")
         eg.messageReceiver.AddHandler(WM_SHELLHOOKMESSAGE, callback)
     if waitForCompletion:
         WaitForSingleObject(processInformation.hProcess, INFINITE)
         exitCode = DWORD()
         if not GetExitCodeProcess(
             processInformation.hProcess,
             byref(exitCode)
         ):
             raise self.Exception(FormatError())
         returnValue = exitCode.value
         if triggerEvent:
             eg.TriggerEvent(suffix, prefix = prefix)
         CloseHandle(processInformation.hProcess)
         CloseHandle(processInformation.hThread)
         return returnValue
     elif triggerEvent:
         te=self.TriggerEvent(processInformation, suffix, prefix)
         te.start()
     else:
         CloseHandle(processInformation.hProcess)
         CloseHandle(processInformation.hThread)