正在加载图片...
17 18曰whi1e1 %GetSecs获取当前电脑系统时间 19 swhile 1 is always true,so this loop will continue indefinitely. 20 Line 28 forceably breaks us out of the loop if the escape key is 21 号pressed 22 23 Check the state of the keyboard. 24 See if a key is currently pressed on the keyboard.If not,we skip 25 s the next for loop from lines 20-38,and basically check again almost 26 &immediately. 27 28 【keyIsDown,seconds,keyCode】=KbCheck; %KbCheck检查是否有按键行为 29 30 If the user is pressing a key, then display its code number and name. 32白 if keyIsDown %如果检测到按键行为,显示按键内容及时间 33 34 Note that we use find(keyCode)because keyCode is an array. 35 str=['You pressed key 'num2str(find(keyCode)),'which is',KbName(keyCode),'typed at time ',. num2str(seconds startsecs),'seconds']: 37 %是字符跨行连接符 8 disp(str); 39 Display which key has been pressed. 40 41 If the key that has been pressed is the escape key break out of all loops including the indefinite while loop. 43白 if keyCode(escapekey) 44 break; %如果检测到的按键行为是结束键,则break, 45 end 96 跳出while7end'死循环 while KbCheck;end If the user holds down a key for more than a microsecond, 49 KbCheck will report multiple events,since computers are faster 50 than people's fingers 51 To condense multiple 'keyDown'events into a single event, 52 tonce a key has been pressed 53 we wait until all keys have been released 54 sbefore going through the loop again 56 end -end 58 Listenchar(0); %KbCheck检查是否有按键行为 %如果检测到按键行为,显示按键内容及时间 %如果检测到的按键行为是结束键,则break, 跳出while 1 end‘死循环’ %GetSecs获取当前电脑系统时间 %.是字符跨行连接符
<<向上翻页向下翻页>>
©2008-现在 cucdc.com 高等教育资讯网 版权所有