time user input as soon as they start typing

4 views (last 30 days)
Peter
Peter on 24 Jan 2014
Commented: Peter on 30 Jan 2014
I'm relatively new to matlab and am struggling to find a means to use a timer to measure the time it takes for a user to type their input in as soon as they start typing. I've looked at using "tic toc" with no luck and sinestream. Would very much appreciate any hints or pointers cheers!

Answers (2)

per isakson
per isakson on 24 Jan 2014
Edited: per isakson on 26 Jan 2014
Comments
  • timer is not appropriate for this job
  • tic, str = user_inputs_data; user_time = toc; should work
How does the user input the data?
.
[Later]
Comments
  • this is far from trivial to do with matlab
  • there has been discussions on how to check the user input while the user is typing. AFAIK: there is no good solution with plain Matlab
  • I think it is possible to achieve with the callbacks of figure: KeyPressFcn etc. [It's not possible when the user types in a uicontrol('Style','Edit').]
  • but first you should see Editbox data input validation
[26 Jan]
  • I'm convinced that with plain Matlab it is not possible to measure the elapsed time from the user's first keystroke to the last of input('iput satetment','s'). The property, KeyPressFcn, does not make it. Neither that of figure nor that of uicontrol('Style','Edit'). Prove me wrong!
  • A low level hack using GUI automation using a Robot might be possible. And search for java.awt.robot at that site.
  • You might be able to find a solution based on an actxcontrol (Create Microsoft ActiveX control in figure window) or Java Matlab-Java book
  • You might want to read about the HG2 update
  1 Comment
Peter
Peter on 24 Jan 2014
through the keybaord. i wa thinking of using input('iput satetment','s') and then as soon as the first signal from the keybaord is received the timer starts and stops when enter is hit. I've used something along the lines of your code already but it doenst do what I'm needing. Thanks very much for you help, any other ideas?

Sign in to comment.


W. Owen Brimijoin
W. Owen Brimijoin on 24 Jan 2014
Per is exactly right, this sort of a question calls for the use of the KeyPressFcn.
The idea is to make a figure that waits for key presses. When the first key is pressed it calls a function that checks what time it is and updates a variable. Afterwards the function ignores any key except 'enter', which causes it to compare the current time to the time the first key was pressed.
If you save the following code as a single function then you should get the behaviour you are looking for:
function keyboard_timer
global typing_detected
typing_detected = 0;
h1 = figure;
set(h1,'KeyPressFcn',@detect_key_event)
function detect_key_event(hObject,~)
global typing_detected
key = get(hObject,'CurrentCharacter'); %get the key that was pressed
switch double(key),
case 13 %this is the ASCII code for the 'enter' key.
elapsed = rem(now - typing_detected,1)*216000; %compare timestamps!
typing_detected = 0;%reset the global variable
display(['Elapsed Time was ',num2str(elapsed)]) %here's the answer
otherwise %any other key triggers this, and if it's the first checks the time
if typing_detected==0,typing_detected = now;end
end
  3 Comments
Peter
Peter on 30 Jan 2014
I take it the elapsed time is measured in seconds then? Is there a way to calibrate this?
Peter
Peter on 30 Jan 2014
Also I'm using this in a uicontrol and there is Current Character property, is there any other property that I can use that Will be equivalent tho it? Thanks very much

Sign in to comment.

Categories

Find more on Historical Contests in Help Center and File Exchange

Products

Community Treasure Hunt

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

Start Hunting!