如何将箭头键转换为ReadKey可以解释的任意单个值?
我尝试了以下代码,但它不起作用:
use Term::ReadKey;ReadMode('cbreak');my $keystroke = '';while ($keystroke ne 'h') { print "Enter key: "; #Read user keystroke $keystroke = ReadKey(0); chomp($keystroke); if(ord($keystroke) == 27) { $keystroke = ('0'); }}
这是基于建议的代码:
use Term::Rawinput;use strict;use warnings;my $keystroke = '';my $special = ''; while(lc($keystroke) ne 'i' && lc($keystroke) ne 't'){ my $promptp = "Enter key: "; ($keystroke,$special) = rawinput($promptp,1); if ($keystroke ne '') { print "You hit the normal '$keystroke' key\n"; } else { print "You hit the special '$special' key\n"; } chomp($keystroke); $keystroke = lc($keystroke);}if($keystroke eq 'i') { #Do something}if($keystroke eq 't') { #Do something}
现在,无论我按什么,我都无法退出这个循环
这是输出:
Enter key: Enter key:Enter key: You hit the normal 't' key#Proceeds to function解决方法
Term::RawInput
并未涵盖所有内容,但这是此任务的良好开端: use Term::Rawinput;my ($keystroke,$special) = rawinput("",1);if ($keystroke ne '') { print "You hit the normal '$keystroke' key\n";} else { print "You hit the special '$special' key\n";}总结
以上是内存溢出为你收集整理的Perl Term :: ReadKey with Arrow Keys全部内容,希望文章能够帮你解决Perl Term :: ReadKey with Arrow Keys所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)