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.LOWORD(lParam) y = winUser.HIWORD(lParam) ID = winUser.LOWORD(wParam) if touching: self.trackerManager.update(ID, x, y, False) elif not flags & POINTER_MESSAGE_FLAG_FIRSTBUTTON: self.trackerManager.update(ID, x, y, True) 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, 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.LOWORD(res), winUser.HIWORD(res)) (left, top, width, height) = self.obj.location point.x = point.x + left point.y = point.y + top return point
def _getOffsetFromPoint(self,x,y): x, y = winUser.ScreenToClient(self.obj.windowHandle, x, y) if self.obj.editAPIVersion>=1: processHandle=self.obj.processHandle internalP=winKernel.virtualAllocEx(processHandle,None,ctypes.sizeof(PointLStruct),winKernel.MEM_COMMIT,winKernel.PAGE_READWRITE) try: p=PointLStruct(x,y) winKernel.writeProcessMemory(processHandle,internalP,ctypes.byref(p),ctypes.sizeof(p),None) offset=watchdog.cancellableSendMessage(self.obj.windowHandle,winUser.EM_CHARFROMPOS,0,internalP) finally: winKernel.virtualFreeEx(processHandle,internalP,0,winKernel.MEM_RELEASE) else: p=x+(y<<16) res=watchdog.cancellableSendMessage(self.obj.windowHandle,winUser.EM_CHARFROMPOS,0,p) offset=winUser.LOWORD(res) lineNum=winUser.HIWORD(res) if offset==0xFFFF and lineNum==0xFFFF: raise LookupError("Point outside client area") if self._getStoryLength() > 0xFFFF: # Returned offsets are 16 bits, therefore for large documents, we need to make sure that the correct offset is returned. # We can calculate this by using the start offset of the line with the retrieved line number. lineStart=watchdog.cancellableSendMessage(self.obj.windowHandle,winUser.EM_LINEINDEX,lineNum,0) # Get the last 16 bits of the line number lineStart16=lineStart&0xFFFF if lineStart16 > offset: # There are cases where the last 16 bits of the line start are greater than the # 16 bits offset. For example, this happens when the line start offset is 65534 (0xFFFE) # and the offset we need ought to be 65537 (0x10001), which is a 17 bits number # In that case, add 0x10000 to the offset, which will make the eventual formula return the correct offset, # unless a line has more than 65535 characters, in which case we can't get a reliable offset. offset+=0x10000 offset = (offset - lineStart16) + lineStart return offset
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.LOWORD(objectID) y=winUser.HIWORD(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=unichr(winUser.LOWORD(childID)))
def handleScreenOrientationChange(self, lParam): import ui import winUser # Resolution detection comes from an article found at https://msdn.microsoft.com/en-us/library/ms812142.aspx. #The low word is the width and hiword is height. width = winUser.LOWORD(lParam) height = winUser.HIWORD(lParam) self.orientationCoordsCache = (width,height) if width > height: # If the height and width are the same, it's actually a screen flip, and we do want to alert of those! if self.orientationStateCache == self.ORIENTATION_LANDSCAPE and self.orientationCoordsCache != (width,height): return #Translators: The screen is oriented so that it is wider than it is tall. ui.message(_("Landscape" )) self.orientationStateCache = self.ORIENTATION_LANDSCAPE else: if self.orientationStateCache == self.ORIENTATION_PORTRAIT and self.orientationCoordsCache != (width,height): return #Translators: The screen is oriented in such a way that the height is taller than it is wide. ui.message(_("Portrait")) self.orientationStateCache = self.ORIENTATION_PORTRAIT