Button click (on/ off) vs tap (touch/ release) on a Touchscreen

13 views (last 30 days)
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 Comments
Walter Roberson
Walter Roberson on 31 Oct 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.
SK
SK on 31 Oct 2018
You are right. But is it possible to control touch/release?

Sign in to comment.

Answers (1)

Walter Roberson
Walter Roberson on 31 Oct 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.

Categories

Find more on Migrate GUIDE Apps in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!