Button click (on/ off) vs tap (touch/ release) on a Touchscreen
11 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Hello,
I need the next script to react to a tap on a touchscreen. Important is to react not on the release but on the touch of the touchscreen. As the smartphones or tablets open apps on a touch of a tap rather than on a release. Initially, I thought that the mouse's button down/up is equivalent to the touch/release of the touchscreen. However, that is not the case.
Here is a script that prints "Position#" of the touch on a rectangle. Using the mouse, the script will print the "Position" after the left mouse button is pressed. Using the touchscreen, the "Position#" will be printed only after the release of the tap.
Do you know how can I control that the "Position#" is printed on a touch (on the touching itself, but not on the release) on the touchscreen?
clear
close all
%%Parameters
figurePosition=[0 0 600 600];% position on the screen
Xmin=1; Xmax=7; % Position of the rectangle on the x-axis
Ymin=2; Ymax=8; % Position of the rectangle on the y-axis
StimPosition=[Xmin Ymin (Xmax-Xmin) (Ymax-Ymin)];
StimAxis=[0 10 0 10]; % Axis settings
StimColor=[0 0.5 0.5]; % Color of the rectangle
%%Additional settings
continue_loop = true;
n=1;
while continue_loop
% Draw a rectangle
hRectangularStimul=rectangle('Position',StimPosition,'FaceColor',StimColor,...
'EdgeColor',StimColor,'LineWidth',3);
axis(StimAxis)
set(gca,'visible','off')
set(gcf,'Position',figurePosition);% show on the second screen
% Graphical input
[x,y]=ginput(1); % get position of touch
% Run if the input was in the rectangle
if x>=Xmin && x<=Xmax && y>=Ymin && y<=Ymax
fprintf(['Position',num2str(n),'\n'])
n=n+1;
end
end
2 comentarios
Walter Roberson
el 31 de Oct. de 2018
"As the smartphones or tablets open apps on a touch of a tap rather than on a release"
That is not correct. They open on the release. That is the only way that they can distinguish long press from tap.
Respuestas (1)
Walter Roberson
el 31 de Oct. de 2018
ButtonDownFcn callbacks fire upon button press, not upon release.
Figure WindowButtonDownFcn and WindowButtonUpFcn callbacks fire upon button press and button release, respectively.
ginput() uses waitforbuttonpress() . Mouse buttons send distinct Press and Release events. Touchscreen do not, because long presses need to be found and long presses are not equivalent to button down.
It would not surprise me at all if WindowButtonDownFcn does not fire upon tap of a touchscreen, waiting until release.
Looking at https://social.msdn.microsoft.com/Forums/en-US/fc7ef4ec-fd32-4167-9c17-6622d1425582/recognizing-a-touchandhold-event-on-a-touchscreen?forum=Vsexpressvb and https://stackoverflow.com/questions/7560334/wm-touch-is-not-immediately-sent-with-touch-down-event I suspect that MATLAB is responding to WM_LBUTTONDOWN events, and that you would need to register specifically for immediate touch events.
You might want to make use of http://profs.etsmtl.ca/mmcguffin/code/java/SimpleRealTimeStrategyGame-2D-Multitouch_JavaApplication-JOGL-OpenGL/doNotCompile/MultitouchFramework-WM_TOUCH.java which appears to be a Java interface to the Windows touch system.
0 comentarios
Ver también
Categorías
Más información sobre Migrate GUIDE Apps en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!