Exemplo n.º 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)
Exemplo n.º 2
0
 def __init__(self):
     ThreadWorker.__init__(self)
     eg.event = EventGhostEvent("")
     self.startupEvent = None
     self.hHandle = OpenProcess(PROCESS_SET_QUOTA, 0, eg.processId)
     self.filters = {}