如何让 MATLAB 检测键盘敲击(箭头)并记录数据?
How to make MATLAB detect keyboard stroke (arrows) and record the data?
我正在尝试编写 MATLAB 代码,在有数字的情况下检测键盘的左右箭头键并记录击键。
double(get(gcf,'currentcharacter'))
我试过上面的功能,但我认为这不是我要找的。
你可以使用 ginput
[~,~,button]=ginput(1);
switch button
case 30 %up
case 31 %down
case 28 %left
case 29 %right
end
我过去写的一些关于数字交互式缩放和平移的东西:
set(gcf,'WindowKeyPressFcn',{@KeyPressd,mean(xlim)});
在'KeyPressd.m'中:
function [ ] = KeyPressd( src,evnt,S0 )
switch evnt.Key
case 'f'
set(gca,'XLim', xlim + range(xlim)/100 );
case 'v'
set(gca,'XLim', xlim - range(xlim)/100 );
case 'h'
set(gca,'YLim', ylim + range(ylim)/100 );
case 'n'
set(gca,'YLim', ylim - range(ylim)/100 );
case 'g'
set(gca,'ZLim', zlim + range(zlim)/100 );
case 'b'
set(gca,'ZLim', zlim - range(zlim)/100 );
case 'd'
set(gca,'XLim', xlim - 0.02*(xlim-sum(xlim)/2) );
case 'c'
set(gca,'XLim', xlim + 0.02*(xlim-sum(xlim)/2) );
case 'a'
set(gca,'YLim', ylim - 0.02*(ylim-sum(ylim)/2) );
case 'z'
set(gca,'YLim', ylim + 0.02*(ylim-sum(ylim)/2) );
case 's'
set(gca,'ZLim', 0.98*(zlim) );
case 'x'
set(gca,'ZLim', 1/0.98*(zlim) );
end
set(gca,'ZTickLabel',sprintf('%1.0f\n',get(gca,'ZTick')));
我正在尝试编写 MATLAB 代码,在有数字的情况下检测键盘的左右箭头键并记录击键。
double(get(gcf,'currentcharacter'))
我试过上面的功能,但我认为这不是我要找的。
你可以使用 ginput
[~,~,button]=ginput(1);
switch button
case 30 %up
case 31 %down
case 28 %left
case 29 %right
end
我过去写的一些关于数字交互式缩放和平移的东西:
set(gcf,'WindowKeyPressFcn',{@KeyPressd,mean(xlim)});
在'KeyPressd.m'中:
function [ ] = KeyPressd( src,evnt,S0 )
switch evnt.Key
case 'f'
set(gca,'XLim', xlim + range(xlim)/100 );
case 'v'
set(gca,'XLim', xlim - range(xlim)/100 );
case 'h'
set(gca,'YLim', ylim + range(ylim)/100 );
case 'n'
set(gca,'YLim', ylim - range(ylim)/100 );
case 'g'
set(gca,'ZLim', zlim + range(zlim)/100 );
case 'b'
set(gca,'ZLim', zlim - range(zlim)/100 );
case 'd'
set(gca,'XLim', xlim - 0.02*(xlim-sum(xlim)/2) );
case 'c'
set(gca,'XLim', xlim + 0.02*(xlim-sum(xlim)/2) );
case 'a'
set(gca,'YLim', ylim - 0.02*(ylim-sum(ylim)/2) );
case 'z'
set(gca,'YLim', ylim + 0.02*(ylim-sum(ylim)/2) );
case 's'
set(gca,'ZLim', 0.98*(zlim) );
case 'x'
set(gca,'ZLim', 1/0.98*(zlim) );
end
set(gca,'ZTickLabel',sprintf('%1.0f\n',get(gca,'ZTick')));