即使使用noecho()之后,用getch()获取的字符也会写入控制台

时间:2018-10-19 04:01:41

标签: python python-3.x python-curses

我目前正在使用文本编辑器。 if userInput == 68行检查用户是否按了左箭头键,我认为代码已运行,但是即使使用^[[noecho()仍会打印出来。这是代码

#!/usr/bin/env python3

from unicurses import * 
from sys import *

stdscr = initscr()
start_color()
use_default_colors()
noecho()

fileLines = []
fileName = "test.txt"
currentY = 0
currentX = 0 
userInput = ""

for i in range(0, 256):
    curses.init_pair(i + 1, i, -1)

while True:

userInput = getch()

if userInput == 68:
    currentX = currentX-1
    move(currentY, currentX)
elif userInput == 127:
    if currentX != 0:
        currentX = currentX-1
        move(currentY, currentX)
        addstr(" ")
        move(currentY, currentX)
    else:
        continue
else:
    addstr(chr(userInput))
    currentX = currentX+1

endwin()

0 个答案:

没有答案