我正在尝试制作MATLAB代码,用于检测键盘的左右箭头键,同时有一个数字并记录击键。
double(get(gcf,'currentcharacter'))
我尝试了以上功能,但我不认为这是我寻找的那个。
答案 0 :(得分:0)
您可以使用ginput
[~,~,button]=ginput(1);
switch button
case 30 %up
case 31 %down
case 28 %left
case 29 %right
end
答案 1 :(得分:0)
我过去写过的用于交互式缩放和数字平移的东西:
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')));