def _getPointFromOffset(self, offset): if self.obj.editAPIVersion == 1 or self.obj.editAPIVersion >= 3: processHandle = self.obj.processHandle internalP = winKernel.virtualAllocEx(processHandle, None, ctypes.sizeof(PointLStruct), winKernel.MEM_COMMIT, winKernel.PAGE_READWRITE) try: p = PointLStruct(0, 0) winKernel.writeProcessMemory(processHandle, internalP, ctypes.byref(p), ctypes.sizeof(p), None) watchdog.cancellableSendMessage(self.obj.windowHandle, EM_POSFROMCHAR, internalP, offset) winKernel.readProcessMemory(processHandle, internalP, ctypes.byref(p), ctypes.sizeof(p), None) finally: winKernel.virtualFreeEx(processHandle, internalP, 0, winKernel.MEM_RELEASE) point = textInfos.Point(p.x, p.y) else: res = watchdog.cancellableSendMessage(self.obj.windowHandle, EM_POSFROMCHAR, offset, None) point = textInfos.Point(winUser.GET_X_LPARAM(res), winUser.GET_Y_LPARAM(res)) (left, top, width, height) = self.obj.location point.x = point.x + left point.y = point.y + top return point
def fromDWORD(cls, dwPoint): if isinstance(dwPoint, DWORD): dwPoint = dwPoint.value if not isinstance(dwPoint, (int, long)): raise TypeError( "dwPoint should be one of int, long or ctypes.wintypes.DWORD (ctypes.ulong)" ) return Point(winUser.GET_X_LPARAM(dwPoint), winUser.GET_Y_LPARAM(dwPoint))
def inputTouchWndProc(self,hwnd,msg,wParam,lParam): if msg>=_WM_POINTER_FIRST and msg<=_WM_POINTER_LAST: flags=winUser.HIWORD(wParam) touching=(flags&POINTER_MESSAGE_FLAG_INRANGE) and (flags&POINTER_MESSAGE_FLAG_FIRSTBUTTON) x=winUser.GET_X_LPARAM(lParam) y=winUser.GET_Y_LPARAM(lParam) ID=winUser.LOWORD(wParam) if touching: self.trackerManager.update(ID,x,y,False) core.requestPump() elif not flags&POINTER_MESSAGE_FLAG_FIRSTBUTTON: self.trackerManager.update(ID,x,y,True) core.requestPump() return 0 return windll.user32.DefWindowProcW(hwnd,msg,wParam,lParam)
def _getPointFromOffset(self, offset): if self.obj.editAPIVersion == 1 or self.obj.editAPIVersion >= 3: processHandle = self.obj.processHandle internalP = winKernel.virtualAllocEx(processHandle, None, ctypes.sizeof(PointLStruct), winKernel.MEM_COMMIT, winKernel.PAGE_READWRITE) try: p = PointLStruct(0, 0) winKernel.writeProcessMemory(processHandle, internalP, ctypes.byref(p), ctypes.sizeof(p), None) watchdog.cancellableSendMessage(self.obj.windowHandle, winUser.EM_POSFROMCHAR, internalP, offset) winKernel.readProcessMemory(processHandle, internalP, ctypes.byref(p), ctypes.sizeof(p), None) finally: winKernel.virtualFreeEx(processHandle, internalP, 0, winKernel.MEM_RELEASE) point = locationHelper.Point(p.x, p.y) else: res = watchdog.cancellableSendMessage(self.obj.windowHandle, winUser.EM_POSFROMCHAR, offset, None) point = locationHelper.Point(winUser.GET_X_LPARAM(res), winUser.GET_Y_LPARAM(res)) # A returned coordinate can be a negative value if # the specified character is not displayed in the edit control's client area. # If the specified index is greater than the index of the last character in the control, # the control returns -1. if point.x < 0 or point.y < 0: raise LookupError( "Point with client coordinates x=%d, y=%d not within client area of object" % (point.x, point.y)) try: return point.toScreen(self.obj.windowHandle) except WindowsError as e: raise LookupError( f"Couldn't convert point at offset {offset} to screen coordinates: {e.strerror}" )
def consoleWinEventHook(handle, eventID, window, objectID, childID, threadID, timestamp): #We don't want to do anything with the event if the event is not for the window this console is in if window != consoleObject.windowHandle: return if eventID == winUser.EVENT_CONSOLE_CARET and not eventHandler.isPendingEvents( "caret", consoleObject): eventHandler.queueEvent("caret", consoleObject) # It is safe to call this event from this callback. # This avoids an extra core cycle. consoleObject.event_textChange() if eventID == winUser.EVENT_CONSOLE_UPDATE_SIMPLE: x = winUser.GET_X_LPARAM(objectID) y = winUser.GET_Y_LPARAM(objectID) consoleScreenBufferInfo = wincon.GetConsoleScreenBufferInfo( consoleOutputHandle) if x < consoleScreenBufferInfo.dwCursorPosition.x and ( y == consoleScreenBufferInfo.dwCursorPosition.y or y == consoleScreenBufferInfo.dwCursorPosition.y + 1): eventHandler.queueEvent("typedCharacter", consoleObject, ch=chr(winUser.LOWORD(childID)))