Reputation: 221
I am trying to make MATLAB code which detect left and right arrow keys of keyboard while there is a figure and record the key strokes.
double(get(gcf,'currentcharacter'))
I tried above function but I don't think it is the one I looked for.
Upvotes: 0
Views: 1754
Reputation: 3697
Something i wrote in the past for interactive zoom and pan in figures:
set(gcf,'WindowKeyPressFcn',{@KeyPressd,mean(xlim)});
And in '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')));
Upvotes: 0
Reputation: 1845
You can use ginput
[~,~,button]=ginput(1);
switch button
case 30 %up
case 31 %down
case 28 %left
case 29 %right
end
Upvotes: 1