def notify_path_change() -> None: send_message_timeout_w = WinDLL('user32', use_last_error=True).SendMessageTimeoutW handle = HWND(0xffff) message = UINT(0x001A) l_param = c_wchar_p('Environment') flags = UINT(0x0002 & 0x0008) timeout = UINT(__class__.notify_timeout) result = send_message_timeout_w(handle, message, None, l_param, flags, timeout, None) if result == 0: raise WinError()
def test_notifying_path_changes(self, WinDLL): path_manager.notify_path_change() WinDLL.assert_called_once_with('user32', use_last_error=True) args = WinDLL.return_value.SendMessageTimeoutW.call_args hwnd, msg, wParam, lParam, fuFlags, uTimeout, lpdwResult = args[0] self.assertEqual(hwnd.value, HWND(0xffff).value) self.assertEqual(msg.value, UINT(0x001A).value) self.assertIsNone(wParam) self.assertEqual(lParam.value, 'Environment') self.assertEqual(fuFlags.value, UINT(0x0002 & 0x0008).value) self.assertEqual(uTimeout.value, UINT(1000).value) self.assertIsNone(lpdwResult)
def fop(files): import ctypes from ctypes.wintypes import HWND, UINT, LPCWSTR, BOOL class SHFILEOPSTRUCTW(ctypes.Structure): _fields_ = [ ("hwnd", HWND), ("wFunc", UINT), ("pFrom", LPCWSTR), ("pTo", LPCWSTR), ("fFlags", ctypes.c_uint), ("fAnyOperationsAborted", BOOL), ("hNameMappings", ctypes.c_uint), ("lpszProgressTitle", LPCWSTR), ] SHFileOperationW = ctypes.windll.shell32.SHFileOperationW SHFileOperationW.argtypes = [ctypes.POINTER(SHFILEOPSTRUCTW)] pFrom = u'\x00'.join(files) + u'\x00' args = SHFILEOPSTRUCTW(wFunc=UINT(3), pFrom=LPCWSTR(pFrom), pTo=None, fFlags=64, fAnyOperationsAborted=BOOL()) out = SHFileOperationW(ctypes.byref(args))
def init(hwnd, wm): """ This function should be called to use other functions in iMON Display API. When the caller application calls this function, API tries to request Display Plug-in Mode to iMON. Parameters --------- hwnd : HWND API will send/post message to this handle. hwnd is a reference to a win32 window, specifically wm : UINT API will send/post message to hwndNoti with this message identifier, such as that created by the win32 api RegisterWindowMessage("IMON_DISPLAY") Returns ------- DSPResult : EnumMember This function will return one of DSPResult DSP_SUCCEEDED enum on success. only returned if succeeded. Raises ------ Exception Raised when any response is return from IMON that is not a success. This can includeDSP_E_INVALIDARG or DSP_E_OUTOFMEMORY errors from the DSPResult Enumorater. """ result = imonDll.IMON_Display_Init(HWND(hwnd), UINT(wm)) if (result == DSPResult.DSP_SUCCEEDED): return result raise Exception, result.name
def register_hotkey(self, wid, keys, callback): mods, kc = keys_from_string(keys) if wid is None: wid = 0x0 # High word = Key code, Low word = Modifiers # https://msdn.microsoft.com/en-us/library/windows/desktop/ms646279%28v=vs.85%29.aspx # Add MOD_NOREPEAT = 0x4000 to mods, so that keys don't get notified twice # This requires VISTA+ operating system key_index = kc << 16 | mods if not self.__keygrabs[key_index] and\ not self.RegisterHotKey(c_int(wid), key_index, UINT(mods | 0x4000), UINT(kc)): print("Couldn't register hot key!") return False self.__keybinds[key_index].append(callback) self.__keygrabs[key_index] += 1 return True
def __init__(self, interval, tickFunc, stopFunc=None, resolution=0, periodic=True): """ Setup a control to be invoked on a fixed interval. :param interval: How frequently in milliseconds to invoke the control. :param tickFunc: The control function to invoke. :param stopFunc: Another control to invoke when the event is stopped. :param resolution: The resolution of the time. :param periodic: Keep invoking the call back or not? """ self.interval = UINT(interval) self.resolution = UINT(resolution) self.tickFunc = tickFunc self.stopFunc = stopFunc self.periodic = periodic self.id = None self.running = False self.calbckfn = timeproc(self._callback)
def _set_exposure(self, exp_time): param = DOUBLE(exp_time.m_as('ms')) cbSizeOfParam = UINT(8) lib.is_Exposure(self._hcam, IS_EXPOSURE_CMD_SET_EXPOSURE, byref(param), cbSizeOfParam) return param
comtypes.CoInitialize() pServiceProvider = comtypes.CoCreateInstance( CLSID_ImmersiveShell, IServiceProvider, comtypes.CLSCTX_LOCAL_SERVER, ) pDesktopManagerInternal = comtypes.cast( pServiceProvider.QueryService(CLSID_VirtualDesktopManagerInternal, IID_IVirtualDesktopManagerInternal), ctypes.POINTER(IVirtualDesktopManagerInternal)) pObjectArray = POINTER(IObjectArray)() pDesktopManagerInternal.GetDesktops(ctypes.byref(pObjectArray)) count = UINT() pObjectArray.GetCount(ctypes.byref(count)) for i in range(count): pDesktop = POINTER(IVirtualDesktop)() pObjectArray.GetAt(i, IID_IVirtualDesktop, ctypes.byref(pDesktop)) id = GUID() pDesktop.GetID(ctypes.byref(id)) print(id)
def sendinput(): ip = INPUT() ''' 0 for mouse 1 for keyboard 2 for hardware ''' ip.type = DWORD(1) ip.type_input.ki.wScan = WORD(0) ip.type_input.ki.time = DWORD(0) ip.type_input.ki.dwExtraInfo = ULONG_PTR(0) sleep(5) for i in range(500): # Press the "Ctrl" key ip.type_input.ki.wVk = WORD(int("11", 16)) ip.type_input.ki.dwFlags = DWORD(0) ctypes.windll.User32.SendInput(UINT(1), byref(ip), c_int(ctypes.sizeof(ip))) ip.type_input.ki.wVk = WORD(int("56", 16)) ip.type_input.ki.dwFlags = DWORD(0) ctypes.windll.User32.SendInput(UINT(1), byref(ip), c_int(ctypes.sizeof(ip))) ip.type_input.ki.wVk = WORD(int("56", 16)) ip.type_input.ki.dwFlags = DWORD(2) ctypes.windll.User32.SendInput(UINT(1), byref(ip), c_int(ctypes.sizeof(ip))) ip.type_input.ki.wVk = WORD(int("11", 16)) ip.type_input.ki.dwFlags = DWORD(2) ctypes.windll.User32.SendInput(UINT(1), byref(ip), c_int(ctypes.sizeof(ip))) sleep(0.1) # Enter ip.type_input.ki.wVk = WORD(13) ip.type_input.ki.dwFlags = DWORD(0) ctypes.windll.User32.SendInput(UINT(1), byref(ip), c_int(ctypes.sizeof(ip))) # Enter ip.type_input.ki.wVk = WORD(13) ip.type_input.ki.dwFlags = DWORD(2) ctypes.windll.User32.SendInput(UINT(1), byref(ip), c_int(ctypes.sizeof(ip))) sleep(0.1) # Enter ip.type_input.ki.wVk = WORD(13) ip.type_input.ki.dwFlags = DWORD(0) ctypes.windll.User32.SendInput(UINT(1), byref(ip), c_int(ctypes.sizeof(ip))) # Enter ip.type_input.ki.wVk = WORD(13) ip.type_input.ki.dwFlags = DWORD(2) ctypes.windll.User32.SendInput(UINT(1), byref(ip), c_int(ctypes.sizeof(ip))) sleep(0.1)
def do(): hWnd = NULL lpText = ctypes.create_unicode_buffer('UNITTESTS') lpCaption = ctypes.create_unicode_buffer('UNITTESTS') uType = UINT(MB_OK) _MessageBoxW(hWnd, lpText, lpCaption, uType)