?? raw_keyboard.py
字號:
# Get the keyboard into raw mode.import termios, sys, os,fcntldef UnBlock(fd) : fl = fcntl.fcntl(fd, fcntl.F_GETFL, 0) fl |= os.O_NONBLOCK fcntl.fcntl(fd, fcntl.F_SETFL, fl)class UnixKeyboard : "Raw input for the duration of the importer" def __init__(self) : self.fd = sys.stdin.fileno() UnBlock(self.fd) self.old = termios.tcgetattr(self.fd) new = termios.tcgetattr(self.fd) new[3] = new[3] & ~termios.ICANON & ~termios.ECHO new[6][termios.VMIN] = 1 new[6][termios.VTIME] = 0 termios.tcsetattr(self.fd, termios.TCSANOW, new) def getch(self): ret = "" try : ret = os.read(self.fd, 1) except OSError, info : if info.errno==11 : pass else : raise sys.exc_type, sys.exc_value return ret def __del__(self) : import termios termios.tcsetattr(self.fd, termios.TCSAFLUSH, self.old)Keyboard = UnixKeyboard()if __name__ == "__main__" : print "Running key echo program" while True : b = Keyboard.getch() sys.stdout.write(b) sys.stdout.flush()
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -