コード例 #1
0
    def __call__(self,
                 hwnd,
                 keystrokeString,
                 useAlternateMethod=False,
                 mode=2):
        keyData = ParseText(keystrokeString)
        if keyData:
            needGetFocus = False
            sendToFront = False
            if hwnd is None:
                sendToFront = True
                hwnd = GetForegroundWindow()
                needGetFocus = True

            dwProcessId = DWORD()
            threadID = GetWindowThreadProcessId(hwnd, byref(dwProcessId))
            processID = dwProcessId.value
            ourThreadID = GetCurrentThreadId()

            # If not, attach our thread's 'input' to the foreground thread's
            if threadID != ourThreadID:
                AttachThreadInput(threadID, ourThreadID, True)

            if needGetFocus:
                hwnd = GetFocus()
            if not sendToFront:
                if GetGUIThreadInfo(0, byref(self.guiTreadInfo)):
                    sendToFront = (self.guiTreadInfo.hwndFocus == hwnd)
                else:
                    sendToFront = False
            if not hwnd:
                hwnd = None
            self.procHandle = OpenProcess(PROCESS_QUERY_INFORMATION, 0,
                                          processID)
            #self.WaitForInputProcessed()

            oldKeyboardState = PBYTE256()
            GetKeyboardState(byref(oldKeyboardState))

            keyData = ParseText(keystrokeString)
            if sendToFront and not useAlternateMethod:
                self.SendRawCodes1(keyData, mode)
            else:
                self.SendRawCodes2(keyData, hwnd, mode)

            SetKeyboardState(byref(oldKeyboardState))
            self.WaitForInputProcessed()
            if threadID != ourThreadID:
                AttachThreadInput(threadID, ourThreadID, False)
            if self.procHandle:
                CloseHandle(self.procHandle)
コード例 #2
0
 def __call__(self, action=0):
     if action == 0:
         show = True
     elif action == 1:
         show = False
     elif action == 2:
         if eg.document.frame:
             if eg.document.frame.GetHandle() == GetForegroundWindow():
                 show = False
             else:
                 show = True
         else:
             show = True
     else:
         return False
     func = (eg.document.ShowFrame if show else eg.document.HideFrame)
     wx.CallAfter(func)
コード例 #3
0
def GetTopLevelOfTargetWindows():
    hwnds = eg.lastFoundWindows
    if not hwnds:
        return [GetForegroundWindow()]
    return list(set([GetAncestor(hwnd, GA_ROOT) for hwnd in hwnds]))
コード例 #4
0
def GetTargetWindows():
    hwnds = eg.lastFoundWindows
    if not hwnds:
        return [GetForegroundWindow()]
    return hwnds
コード例 #5
0
ファイル: Execute.py プロジェクト: egtopix/EventGhost
    def __call__(
        self,
        pathname='',
        arguments='',
        winState=0,
        waitForCompletion=False,
        priority=2,
        workingDir="",
        triggerEvent=False,
        disableWOW64=False,
        additionalSuffix="",
        disableParsingPathname=False,
        disableParsingArguments=False,
        disableParsingAdditionalSuffix=False,
        runAsAdmin=False,
    ):
        if eg.config.refreshEnv:
            eg.Environment.Refresh()
        returnValue = None
        pathname = expandvars(pathname)
        arguments = expandvars(arguments)
        workingDir = expandvars(workingDir)
        if not disableParsingPathname:
            pathname = eg.ParseString(pathname)
        if not disableParsingArguments:
            arguments = eg.ParseString(arguments)
        if not disableParsingAdditionalSuffix:
            additionalSuffix = eg.ParseString(additionalSuffix)
        if not workingDir:
            workingDir = dirname(abspath(pathname))
        processInformation = self.processInformation = SHELLEXECUTEINFO()
        processInformation.cbSize = sizeof(processInformation)
        processInformation.hwnd = 0
        processInformation.lpFile = pathname
        processInformation.lpParameters = arguments
        processInformation.lpDirectory = workingDir
        processInformation.nShow = WINSTATE_FLAGS[winState]
        processInformation.hInstApp = 0
        processInformation.fMask = SEE_MASK_NOCLOSEPROCESS
        if runAsAdmin:
            processInformation.lpVerb = "runas"
        disableWOW64 = disableWOW64 and IsWin64()
        if disableWOW64:
            prevVal = Wow64DisableWow64FsRedirection()
        activeThread = GetWindowThreadProcessId(GetForegroundWindow(), None)
        currentThread = GetCurrentThreadId()
        attached = AttachThreadInput(currentThread, activeThread, True)

        if not windll.shell32.ShellExecuteExW(byref(processInformation)):
            raise self.Exception(FormatError())

        if attached:
            AttachThreadInput(currentThread, activeThread, False)
        if disableWOW64:
            Wow64RevertWow64FsRedirection(prevVal)
        if priority != 2:
            try:
                SetPriorityClass(processInformation.hProcess,
                                 PRIORITY_FLAGS[priority])
                priorityClass = GetPriorityClass(processInformation.hProcess)
                if priorityClass != PRIORITY_FLAGS[priority]:
                    raise
            except:
                pid = windll.kernel32.GetProcessId(processInformation.hProcess)
                pi = SHELLEXECUTEINFO()
                pi.cbSize = sizeof(pi)
                pi.lpFile = r"C:\Windows\System32\wbem\wmic.exe"
                pi.lpParameters = (
                    "process where processid=%d CALL setpriority %d" %
                    (pid, PRIORITY_FLAGS[priority]))
                pi.lpVerb = "runas"
                if not windll.shell32.ShellExecuteExW(byref(pi)):
                    eg.PrintError(self.text.priorityIssue)
        suffix = "%s.%s" % (self.text.eventSuffix, splitext(
            split(pathname)[1])[0])
        if additionalSuffix != "":
            suffix = suffix + "." + additionalSuffix
        prefix = self.plugin.name.replace(' ', '')
        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)
            return returnValue
        elif triggerEvent:
            te = self.TriggerEvent(processInformation, suffix, prefix)
            te.start()
        else:
            CloseHandle(processInformation.hProcess)