python中回车用什么表示_解释stdscr中的“ENTER”键(Python中的curses模块)

What is the reason for that?

您需要调用curses.noecho()作为初始化的一部分。Is there a way to move the curse to the next line?

stdscr.move(y,x)将移动到绝对位置。stdscr.getyx()将告诉您当前位置。If I want to do certain things (execute some function or something) on enter key press, then what will come in 'if'condition? e.g.

你会认为你可以调用getch(),并将结果与KEY_ENTER进行比较。实际上,你需要检查更多的值。根据终端设置、使用的库和月相,可能需要检查换行符(也称为\n、^J、ASCII 10)或回车符(\r、^M、ASCII 13)。c = stdscr.getch()

if c == curses.KEY_ENTER or c == 10 or c == 13:

# I hit ENTER

示例程序:import curses

# Thanks, http://www.ipsum-generator.com

ipsum = '''Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer

nec odio. Praesent libero. Sed cursus ante dapibus diam. Sed nisi. Nulla

quis sem at nibh elementum imperdiet. Duis sagittis ipsum. Praesent

mauris. Fusce nec tellus sed augue semper porta. Mauris massa. Vestibulum

lacinia arcu eget nulla. Class aptent taciti sociosqu ad litora torquent

per conubia nostra, per inceptos himenaeos.'''

try:

# Standard startup. Probably don't need to change this

stdscr = curses.initscr()

curses.cbreak()

curses.noecho()

stdscr.keypad(1)

# Silly program to write to the screen,

# wait for either or .

# On , mess with the screen.

# On , exit.

stdscr.addstr(0, 0, ipsum)

stdscr.move(0, 0)

stdscr.refresh()

i = 0

j = 0

while 1:

c = stdscr.getch()

if c == ord('q'):

exit(0)

if c == curses.KEY_ENTER or c == 10 or c == 13:

i += 1

if i % 3 == 0:

stdscr.addstr(0, 0, ipsum.lower())

if i % 3 == 1:

stdscr.addstr(0, 0, ipsum.upper())

if i % 3 == 2:

stdscr.addstr(0, 0, ipsum)

stdscr.move(0, 0)

if c == curses.KEY_DOWN:

y, x = stdscr.getyx()

maxy, maxx = stdscr.getmaxyx()

stdscr.move((y+1) % maxy, x)

stdscr.refresh()

finally:

# Standard shutdown. Probably don't need to change this.

curses.nocbreak()

stdscr.keypad(0)

curses.echo()

curses.endwin()

参考:

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值