time user input as soon as they start typing

조회 수: 3 (최근 30일)
Peter
Peter 2014년 1월 24일
댓글: Peter 2014년 1월 30일
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!

답변 (2개)

per isakson
per isakson 2014년 1월 24일
편집: per isakson 2014년 1월 26일
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
Peter
Peter 2014년 1월 24일
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?

댓글을 달려면 로그인하십시오.


W. Owen Brimijoin
W. Owen Brimijoin 2014년 1월 24일
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
Peter
Peter 2014년 1월 30일
I take it the elapsed time is measured in seconds then? Is there a way to calibrate this?
Peter
Peter 2014년 1월 30일
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

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Historical Contests에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by