English 中文(简体)
玻璃天花板
原标题:
  • 时间:2009-05-12 19:19:37
  •  标签:

是否有任何办法,可在沙里,以方案方式change。 CPS LOCK/NUM LOCK/SCROL LOCK指出?

这确实是一个小 question问题,更像一个真正的 j.方案问题。 我打算利用它来使灯光避免任何事情。

最佳回答

如果你重新使用窗户,你可以使用

http://www.rutherfurd.net/python/sendkeys

import SendKeys

SendKeys.SendKeys("""
{CAPSLOCK}
{SCROLLOCK}
{NUMLOCK}
""")
问题回答

这里的Libert,是一条连接所有关键排泄板的“灰色”方案:

import fcntl
import os
import time

KDSETLED = 0x4B32
SCR_LED  = 0x01
NUM_LED  = 0x02
CAP_LED  = 0x04

console_fd = os.open( /dev/console , os.O_NOCTTY)

all_on = SCR_LED | NUM_LED | CAP_LED
all_off = 0

while 1:
    fcntl.ioctl(console_fd, KDSETLED, all_on)
    time.sleep(1)
    fcntl.ioctl(console_fd, KDSETLED, all_off)
    time.sleep(1)

可能不会对《任择议定书》有用,但值得作为人分享,可能会像现在这样寻找答案,但不能在没有使用第三方模块的情况下找到解决办法。 这正是把帽子上锁起来的。

import ctypes

def turn_capslock():
    dll = ctypes.WinDLL( User32.dll )
    VK_CAPITAL = 0X14
    if not dll.GetKeyState(VK_CAPITAL):
        dll.keybd_event(VK_CAPITAL, 0X3a, 0X1, 0)
        dll.keybd_event(VK_CAPITAL, 0X3a, 0X3, 0)

    return dll.GetKeyState(VK_CAPITAL)
print(turn_capslock())

For Windows:

#https://stackoverflow.com/questions/21549847/send-key-combination-with-python
#https://msdn.microsoft.com/en-us/library/8c6yea83(v=vs.84).aspx 

import win32com.client as comclt
wsh= comclt.Dispatch("WScript.Shell")
wsh.SendKeys("abc") #types out abc directly into wherever you have your cursor (ex: right into this editor itself!)

wsh.SendKeys("{NUMLOCK}{CAPSLOCK}{SCROLLLOCK}") #toggles the state of NumLock, CapsLock, and ScrollLock; remove whichever one you don t want to toggle

来源:

  1. Send key combination with python
  2. https://msdn.microsoft.com/en-us/library/8c6yea83(v=vs.84).aspx

此外,还认真关注Uri如何读到CapsLock州的问题。 为了建立一个专门针对真实或虚假的无酬国家,你只能盲目地 to,你们必须知道目前的状况是谁。 他向你们展示了如何读到CapsLock邦。 这里读到所有3个最不发达国家:

#https://stackoverflow.com/questions/854393/change-keyboard-locks-in-python/854442#854442abc
#https://support.microsoft.com/en-us/kb/177674
import win32api,win32con

def isCapsLockOn():
    "return 1 if CapsLock is ON"
    return win32api.GetKeyState(win32con.VK_CAPITAL)

def isNumLockOn():
    "return 1 if NumLock is ON"
    return win32api.GetKeyState(win32con.VK_NUMLOCK)

def isScrollLockOn():
    "return 1 if ScrollLock is ON"
    return win32api.GetKeyState(win32con.VK_SCROLL)

print("IsCapsLockOn = ", IsCapsLockOn())
print("isNumLockOn = ", isNumLockOn())
print("isScrollLockOn = ", isScrollLockOn())

For Linux:

Don t了解所有细节,但在此开始:

Is there a generic Python module for any OS?

不详。

Related:

  1. How to generate keyboard events in Python? - I need to look into this.
  2. https://pypi.org/project/keyboard/ - looks like it requires sudo for Linux. That s not good, but I need to look into it more.
  3. Another Windows-only module it looks like: https://pypi.org/project/SendKeys/

利用SendKeys将CAPS LOCK确定为一种特定价值,首先必须检测CAPS LOCK的状况。 在这里,如何在晚上(窗口下)这样做:

import win32api,win32con

def IsCapsLockOn():
    # return 1 if CAPSLOCK is ON
    return win32api.GetKeyState(win32con.VK_CAPITAL)

Use this:

from win32api import GetKeyState
from win32con import VK_CAPITAL

GetKeyState(VK_CAPITAL)

1 == True 0 == False

You can get other keys as well, here is the list: https://learn.microsoft.com/en-au/windows/win32/inputdev/virtual-key-codes





相关问题
热门标签