当前位置: 首页>>代码示例>>Python>>正文


Python ctypes.windll方法代码示例

本文整理汇总了Python中ctypes.windll方法的典型用法代码示例。如果您正苦于以下问题:Python ctypes.windll方法的具体用法?Python ctypes.windll怎么用?Python ctypes.windll使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ctypes的用法示例。


在下文中一共展示了ctypes.windll方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: handle_input

# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import windll [as 别名]
def handle_input(self, ncode, wparam, lparam):
        """Process the key input."""
        value = WIN_KEYBOARD_CODES[wparam]
        scan_code = lparam.contents.scan_code
        vk_code = lparam.contents.vk_code
        self.update_timeval()

        events = []
        # Add key event
        scan_key, key_event = self.emulate_press(
            vk_code, scan_code, value, self.timeval)
        events.append(scan_key)
        events.append(key_event)

        # End with a sync marker
        events.append(self.sync_marker(self.timeval))

        # We are done
        self.write_to_pipe(events)

        return ctypes.windll.user32.CallNextHookEx(
            self.hooked, ncode, wparam, lparam) 
开发者ID:zeth,项目名称:inputs,代码行数:24,代码来源:inputs.py

示例2: delay_and_stop

# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import windll [as 别名]
def delay_and_stop(duration, dll, device_number):
    """Stop vibration aka force feedback aka rumble on
    Windows after duration miliseconds."""
    xinput = getattr(ctypes.windll, dll)
    time.sleep(duration/1000)
    xinput_set_state = xinput.XInputSetState
    xinput_set_state.argtypes = [
        ctypes.c_uint, ctypes.POINTER(XinputVibration)]
    xinput_set_state.restype = ctypes.c_uint
    vibration = XinputVibration(0, 0)
    xinput_set_state(device_number, ctypes.byref(vibration))


# I made this GamePad class before Mouse and Keyboard above, and have
# learned a lot about Windows in the process.  This can probably be
# simplified massively and made to match Mouse and Keyboard more. 
开发者ID:zeth,项目名称:inputs,代码行数:18,代码来源:inputs.py

示例3: _find_xinput

# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import windll [as 别名]
def _find_xinput(self):
        """Find most recent xinput library."""
        for dll in XINPUT_DLL_NAMES:
            try:
                self.xinput = getattr(ctypes.windll, dll)
            except OSError:
                pass
            else:
                # We found an xinput driver
                self.xinput_dll = dll
                break
        else:
            # We didn't find an xinput library
            warn(
                "No xinput driver dll found, gamepads not supported.",
                RuntimeWarning) 
开发者ID:zeth,项目名称:inputs,代码行数:18,代码来源:inputs.py

示例4: EnumWindows

# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import windll [as 别名]
def EnumWindows():
    _EnumWindows = windll.user32.EnumWindows
    _EnumWindows.argtypes = [WNDENUMPROC, LPARAM]
    _EnumWindows.restype = bool

    EnumFunc = __EnumWndProc()
    lpEnumFunc = WNDENUMPROC(EnumFunc)
    if not _EnumWindows(lpEnumFunc, NULL):
        errcode = GetLastError()
        if errcode not in (ERROR_NO_MORE_FILES, ERROR_SUCCESS):
            raise ctypes.WinError(errcode)
    return EnumFunc.hwnd


# BOOL CALLBACK EnumChildProc(
#     HWND hwnd,
#     LPARAM lParam
# ); 
开发者ID:cb109,项目名称:sublime3dsmax,代码行数:20,代码来源:winapi.py

示例5: EnumChildWindows

# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import windll [as 别名]
def EnumChildWindows(hWndParent=NULL):
    _EnumChildWindows = windll.user32.EnumChildWindows
    _EnumChildWindows.argtypes = [HWND, WNDENUMPROC, LPARAM]
    _EnumChildWindows.restype = bool

    EnumFunc = __EnumChildProc()
    lpEnumFunc = WNDENUMPROC(EnumFunc)
    SetLastError(ERROR_SUCCESS)
    _EnumChildWindows(hWndParent, lpEnumFunc, NULL)
    errcode = GetLastError()
    if errcode != ERROR_SUCCESS and errcode not in \
            (ERROR_NO_MORE_FILES, ERROR_SUCCESS):
        raise ctypes.WinError(errcode)
    return EnumFunc.hwnd


# int WINAPI GetWindowText(
#   __in   HWND hWnd,
#   __out  LPTSTR lpString,
#   __in   int nMaxCount
# ); 
开发者ID:cb109,项目名称:sublime3dsmax,代码行数:23,代码来源:winapi.py

示例6: GetWindowTextA

# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import windll [as 别名]
def GetWindowTextA(hWnd):
    _GetWindowTextA = windll.user32.GetWindowTextA
    _GetWindowTextA.argtypes = [HWND, LPSTR, ctypes.c_int]
    _GetWindowTextA.restype = ctypes.c_int

    nMaxCount = 0x1000
    dwCharSize = sizeof(CHAR)
    while 1:
        lpString = ctypes.create_string_buffer(nMaxCount)
        nCount = _GetWindowTextA(hWnd, lpString, nMaxCount)
        if nCount == 0:
            raise ctypes.WinError()
        if nCount < nMaxCount - dwCharSize:
            break
        nMaxCount += 0x1000
    return str(lpString.value) 
开发者ID:cb109,项目名称:sublime3dsmax,代码行数:18,代码来源:winapi.py

示例7: GetClassNameA

# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import windll [as 别名]
def GetClassNameA(hWnd):
    _GetClassNameA = windll.user32.GetClassNameA
    _GetClassNameA.argtypes = [HWND, LPSTR, ctypes.c_int]
    _GetClassNameA.restype = ctypes.c_int

    nMaxCount = 0x1000
    dwCharSize = sizeof(CHAR)
    while 1:
        lpClassName = ctypes.create_string_buffer(nMaxCount)
        nCount = _GetClassNameA(hWnd, lpClassName, nMaxCount)
        if nCount == 0:
            raise ctypes.WinError()
        if nCount < nMaxCount - dwCharSize:
            break
        nMaxCount += 0x1000
    return str(lpClassName.value) 
开发者ID:cb109,项目名称:sublime3dsmax,代码行数:18,代码来源:winapi.py

示例8: GetClassNameW

# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import windll [as 别名]
def GetClassNameW(hWnd):
    _GetClassNameW = windll.user32.GetClassNameW
    _GetClassNameW.argtypes = [HWND, LPWSTR, ctypes.c_int]
    _GetClassNameW.restype = ctypes.c_int

    nMaxCount = 0x1000
    dwCharSize = sizeof(WCHAR)
    while 1:
        lpClassName = ctypes.create_unicode_buffer(nMaxCount)
        nCount = _GetClassNameW(hWnd, lpClassName, nMaxCount)
        if nCount == 0:
            raise ctypes.WinError()
        if nCount < nMaxCount - dwCharSize:
            break
        nMaxCount += 0x1000
    return str(lpClassName.value) 
开发者ID:cb109,项目名称:sublime3dsmax,代码行数:18,代码来源:winapi.py

示例9: test_find_microbit_nt_exists

# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import windll [as 别名]
def test_find_microbit_nt_exists():
    """
    Simulate being on os.name == 'nt' and a disk with a volume name 'MICROBIT'
    exists indicating a connected micro:bit device.
    """
    mock_windll = mock.MagicMock()
    mock_windll.kernel32 = mock.MagicMock()
    mock_windll.kernel32.GetVolumeInformationW = mock.MagicMock()
    mock_windll.kernel32.GetVolumeInformationW.return_value = None
    #
    # Have every drive claim to be removable
    #
    mock_windll.kernel32.GetDriveTypeW = mock.MagicMock()
    mock_windll.kernel32.GetDriveTypeW.return_value = 2
    with mock.patch('os.name', 'nt'):
        with mock.patch('os.path.exists', return_value=True):
            return_value = ctypes.create_unicode_buffer('MICROBIT')
            with mock.patch('ctypes.create_unicode_buffer',
                            return_value=return_value):
                ctypes.windll = mock_windll
                assert uflash.find_microbit() == 'A:\\' 
开发者ID:ntoll,项目名称:uflash,代码行数:23,代码来源:test_uflash.py

示例10: test_find_microbit_nt_missing

# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import windll [as 别名]
def test_find_microbit_nt_missing():
    """
    Simulate being on os.name == 'nt' and a disk with a volume name 'MICROBIT'
    does not exist for a micro:bit device.
    """
    mock_windll = mock.MagicMock()
    mock_windll.kernel32 = mock.MagicMock()
    mock_windll.kernel32.GetVolumeInformationW = mock.MagicMock()
    mock_windll.kernel32.GetVolumeInformationW.return_value = None
    with mock.patch('os.name', 'nt'):
        with mock.patch('os.path.exists', return_value=True):
            return_value = ctypes.create_unicode_buffer(1024)
            with mock.patch('ctypes.create_unicode_buffer',
                            return_value=return_value):
                ctypes.windll = mock_windll
                assert uflash.find_microbit() is None 
开发者ID:ntoll,项目名称:uflash,代码行数:18,代码来源:test_uflash.py

示例11: _copyWindows

# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import windll [as 别名]
def _copyWindows(text):
    GMEM_DDESHARE = 0x2000
    CF_UNICODETEXT = 13
    d = ctypes.windll # cdll expects 4 more bytes in user32.OpenClipboard(None)
    try:  # Python 2
        if not isinstance(text, unicode):
            text = text.decode('mbcs')
    except NameError:
        if not isinstance(text, str):
            text = text.decode('mbcs')
    d.user32.OpenClipboard(None)
    d.user32.EmptyClipboard()
    hCd = d.kernel32.GlobalAlloc(GMEM_DDESHARE, len(text.encode('utf-16-le')) + 2)
    pchData = d.kernel32.GlobalLock(hCd)
    ctypes.cdll.msvcrt.wcscpy(ctypes.c_wchar_p(pchData), text)
    d.kernel32.GlobalUnlock(hCd)
    d.user32.SetClipboardData(CF_UNICODETEXT, hCd)
    d.user32.CloseClipboard() 
开发者ID:mcgreentn,项目名称:GDMC,代码行数:20,代码来源:pyperclip.py

示例12: _get_window_class

# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import windll [as 别名]
def _get_window_class(hwnd):
  """Returns the class name of |hwnd|."""
  ctypes.windll.user32.GetClassNameW.restype = ctypes.c_int
  ctypes.windll.user32.GetClassNameW.argtypes = [
      ctypes.c_void_p,  # HWND
      ctypes.c_wchar_p,
      ctypes.c_int
  ]
  name = ctypes.create_unicode_buffer(257)
  name_len = ctypes.windll.user32.GetClassNameW(hwnd, name, len(name))
  if name_len <= 0 or name_len >= len(name):
    raise ctypes.WinError(descr='GetClassNameW failed; %s' %
                          ctypes.FormatError())
  return name.value


## Public API. 
开发者ID:luci,项目名称:luci-py,代码行数:19,代码来源:win.py

示例13: get_physical_ram

# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import windll [as 别名]
def get_physical_ram():
  """Returns the amount of installed RAM in Mb, rounded to the nearest number.
  """

  # https://msdn.microsoft.com/library/windows/desktop/aa366589.aspx
  class MemoryStatusEx(ctypes.Structure):
    _fields_ = [
        ('dwLength', ctypes.c_ulong),
        ('dwMemoryLoad', ctypes.c_ulong),
        ('dwTotalPhys', ctypes.c_ulonglong),
        ('dwAvailPhys', ctypes.c_ulonglong),
        ('dwTotalPageFile', ctypes.c_ulonglong),
        ('dwAvailPageFile', ctypes.c_ulonglong),
        ('dwTotalVirtual', ctypes.c_ulonglong),
        ('dwAvailVirtual', ctypes.c_ulonglong),
        ('dwAvailExtendedVirtual', ctypes.c_ulonglong),
    ]
  stat = MemoryStatusEx()
  stat.dwLength = ctypes.sizeof(MemoryStatusEx)  # pylint: disable=W0201
  ctypes.windll.kernel32.GlobalMemoryStatusEx(ctypes.byref(stat))
  return int(round(stat.dwTotalPhys / 1024. / 1024.)) 
开发者ID:luci,项目名称:luci-py,代码行数:23,代码来源:win.py

示例14: FormatError

# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import windll [as 别名]
def FormatError(code):
        code = int(long(code))
        try:
            if GuessStringType.t_default == GuessStringType.t_ansi:
                FormatMessage = windll.kernel32.FormatMessageA
                FormatMessage.argtypes = [DWORD, LPVOID, DWORD, DWORD, LPSTR, DWORD]
                FormatMessage.restype  = DWORD
                lpBuffer = ctypes.create_string_buffer(1024)
            else:
                FormatMessage = windll.kernel32.FormatMessageW
                FormatMessage.argtypes = [DWORD, LPVOID, DWORD, DWORD, LPWSTR, DWORD]
                FormatMessage.restype  = DWORD
                lpBuffer = ctypes.create_unicode_buffer(1024)
            ##FORMAT_MESSAGE_FROM_SYSTEM = 0x00001000
            ##FORMAT_MESSAGE_IGNORE_INSERTS = 0x00000200
            success = FormatMessage(0x1200, None, code, 0, lpBuffer, 1024)
            if success:
                return lpBuffer.value
        except Exception:
            pass
        if GuessStringType.t_default == GuessStringType.t_ansi:
            return "Error code 0x%.8X" % code
        return u"Error code 0x%.8X" % code 
开发者ID:debasishm89,项目名称:OpenXMolar,代码行数:25,代码来源:__init__.py

示例15: _copy_windows

# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import windll [as 别名]
def _copy_windows(text, clear=0):
    GMEM_DDESHARE = 0x2000
    CF_UNICODETEXT = 13
    d = ctypes.windll  # cdll expects 4 more bytes in user32.OpenClipboard(0)
    if not isinstance(text, unicode):
        text = text.decode('mbcs')

    d.user32.OpenClipboard(0 if is_python2() else None)

    d.user32.EmptyClipboard()
    hCd = d.kernel32.GlobalAlloc(GMEM_DDESHARE, len(text.encode('utf-16-le')) + 2)
    pchData = d.kernel32.GlobalLock(hCd)
    ctypes.cdll.msvcrt.wcscpy(ctypes.c_wchar_p(pchData), text)
    d.kernel32.GlobalUnlock(hCd)
    d.user32.SetClipboardData(CF_UNICODETEXT, hCd)
    d.user32.CloseClipboard() 
开发者ID:marcwebbie,项目名称:passpie,代码行数:18,代码来源:clipboard.py


注:本文中的ctypes.windll方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。