temporal resolution & screenmouseloc

Anything beyond the basics in using the LiveCode language. Share your handlers, functions and magic here.

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
MMoeller
Posts: 13
Joined: Tue Apr 19, 2011 12:30 pm

temporal resolution & screenmouseloc

Post by MMoeller » Tue May 17, 2011 1:34 pm

Hi all,

I use revolution Studio (build 950, Version 4.0.0) for academic purposes (behavioral experiments with reaction times) and I have a problem with the screenmouseloc-command when it's used within a repeat-structure. I like to locate the mousecursor every millisecond until a defined condition is met and save it's coordinates in a variable. This is the relevant portion of the code:

Code: Select all

repeat until sTrack is false
    put the screenmouseloc & tab after line k of cMouseXY
    wait 1 millisecond
    [...]
end repeat
It thought this would be an easy solution for this purpose. But there is a problem: Even though revolution reports a pair of coordinates every millisecond the first x coordinates are alle the same even if the mouse moves at the beginning of the repeat-structure. Here is an expample of the variable after the repeat-loop ends:

960,600 1
960,600 2
[...]
960,600 203
[...]

The first column denotes the coordinates, the second contains the milliseconds since the start of the repeat-loop. Even though I move the mouse continously the same coordinate is written to the variable for 203 milliseconds. Since temporal resolution is an issue in my domain I like to know if someone has an idea of what causes this problem.

Thanks a lot in advance for your ideas!

Malte

Klaus
Posts: 14198
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: temporal resolution & screenmouseloc

Post by Klaus » Tue May 17, 2011 1:57 pm

Hallo Malte,

problem is that "repeat until..." is of course getting sent even if the mouse does not move!

To prevent this, use the "mousemove" messages instead:

Code: Select all

global/local sTrack ##??
on mousemove
   if sTrack = true then
    ## Other conditons here if neccessary...
     exit mousemove
   end if
  put the screenmouseloc & tab after line k of cMouseXY
end mousemove
No "wait" and no "repeat until" which is always potentially dangerous 8)


Best from the schönes Rheinland :)

Klaus

MMoeller
Posts: 13
Joined: Tue Apr 19, 2011 12:30 pm

Re: temporal resolution & screenmouseloc

Post by MMoeller » Wed May 18, 2011 8:52 am

Hi Klaus,

thanks for your quick answer. I tried a solution with "mouseMove" but then I encounterd a problem with the temporal resolution of the "mouseMove"-message. This is the handler:

Code: Select all

on mouseMove
   put the screenmouseloc & tab & the milliseconds & cr after cMouseXY
end mouseMove
When I move the cursor over a button with an "on MouseMove"-handler in it's object script, the handler writes the coordinates of the cursor and the milliseconds since the start into variable cMouseXY. This is an example of cMouseXY after mouseMove:

999,416 1305704653572
989,410 1305704653589
981,405 1305704653606
971,397 1305704653622

My problem is that the temporal resolution of mouseMove seems to be about 17 ms. Is there a way to reduce the minimal time between the detection of the cursorposition without using the critical "repeat until" and "wait"-commands? I tried "idleRate", but the dictionary says, that it has no effect on this message.

Any ideas?

Thanks a lot!

Malte

jmburnod
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2729
Joined: Sat Dec 22, 2007 5:35 pm
Contact:

Re: temporal resolution & screenmouseloc

Post by jmburnod » Wed May 18, 2011 9:29 am

Hi Malte,
Klaus.
Best from the schönes Rheinland
Fortunately, the german staff is on the beach :shock: . I can answer before them :D
When I move the cursor over a button with an "on MouseMove"-handler in it's object script, the handler writes the coordinates of the cursor and the milliseconds since the start into variable cMouseXY
I think you need a "pass mousemove" in the script of the objects.

Objects script

Code: Select all

on mousemove x,y
  --// What you want
   pass mousemove
end mousemove
Card script

Code: Select all

on mousemove x,y
  --//put x,y & tab & the milliseconds & cr after cMouseXY -- also possible  ?
   put the screenmouseloc & tab & the milliseconds & cr after cMouseXY
end mousemove
All the best
Jean-Marc
Last edited by jmburnod on Thu May 19, 2011 2:42 pm, edited 1 time in total.
https://alternatic.ch

Klaus
Posts: 14198
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: temporal resolution & screenmouseloc

Post by Klaus » Wed May 18, 2011 12:19 pm

Yep! :D

Jean-Marc, unfortunately no beach here 8)

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4172
Joined: Sun Jan 07, 2007 9:12 pm

Re: temporal resolution & screenmouseloc

Post by bn » Wed May 18, 2011 12:49 pm

Hi Malte,

do you absolutely need a 1 millisecond temporal resolution? What would be the minumum otherwise.


But here is a test.

make a button and a field.
Set the script of the button to this:

Code: Select all

local sIShouldSample
local sSamples

on mouseEnter
   put true into sIShouldSample
   put "" into sSamples
   send goSample to me in 0 milliseconds
end mouseEnter

on goSample
   if sIShouldSample then
      put the screenmouseLoc & tab & the milliseconds & cr after sSamples
      if "goSample" is not in the pendingmessages then 
         send "goSample" to me in 1 millisecond
      end if
   end if
end goSample

on mouseLeave
   put false into sIShouldSample
   put sSamples into field 1
end mouseLeave
You will have some latency starting and stopping the handler, mouseEnter is just an example and not a very good one at that, I don't know what the temporal resolution of the screenmouseLoc is.
E.g. it is easy to go very fast over the field and mouseEnter might not even get triggered. I think if you really need 1 millisecond you have to carefully test your code need a fast computer etc if you want to do it with high reliability in Livecode. Even then you might miss some events.

Kind regards from the beautiful beaches of the River Ruhr. (or from the wetland pastures...)

Bernd

MMoeller
Posts: 13
Joined: Tue Apr 19, 2011 12:30 pm

Re: temporal resolution & screenmouseloc

Post by MMoeller » Wed May 18, 2011 1:27 pm

Hi fellow LiveCoders and thanks a lot for your support and good ideas!

@ Bernd:I've tried your test and it turns out that the screenmouseloc can only be reported every 16 milliseconds. There is always a 16 ms gap between different coordinates with identical coordinates for an interval of 16 ms.
@ Jean-Marc: Same holds true for the mouveMove-Handler with pass mouseMove as far as I've tested (although the variable contains only different coordinates which is nice!)

Seems like this is a boundary set by revolution. It's too bad because 16 ms is too high for my purposes because we are looking for a reaction time difference between groups that is about this size.

I'm very thankful for your ideas and support. I've learned a lot by using your codes and thinking about your suggestions.

Thanks for the nice input! Hope I might help sometimes! If I succeed in implementing a 1 ms latency then I will post it immediately.

If there are any ideas left - let me know!

Cheers!

Malte (waiting for the sun popping out of the wall of clouds in Nordrhein-Westfalen)

Regulae
Posts: 136
Joined: Tue Oct 20, 2009 6:05 am

Re: temporal resolution & screenmouseloc

Post by Regulae » Wed May 18, 2011 6:52 pm

Hi there,

I think the problem you've raised is somewhat subtle, but the term "temporal resolution" is a good way to describe it. This may be off the mark, but some years ago I hit a problem where I couldn't seem to detect on-screen motion, which is a change in position over time, within a shorter time interval than 8ms. No amount of recoding seemed to improve on this. The number "8ms" sounded familiar, and indeed it turned out to be the "refresh rate" of my computer screen. So the rate at which the screen redraws imposes an essential "granularity" to motion and its detection. This is a hardware constraint, outside the control of LiveCode. I modified Bernd's elegant script to report only when the mouse position was detected as having changed, by storing the screenMouseLoc in a variable oldLoc, for each "cycle" of the detector handler goSample:

Code: Select all

local sIShouldSample
local sSamples
local oldLoc

on mouseEnter
   put true into sIShouldSample
   put "" into sSamples
   put the screenMouseLoc into oldLoc
   send goSample to me in 0 milliseconds
end mouseEnter

on goSample
   if sIShouldSample then
      put the screenMouseLoc into newLoc
      if newLoc <> oldLoc then
         put the screenmouseLoc & tab & the milliseconds & cr after sSamples
      end if 
      put newLoc into oldLoc
      if "goSample" is not in the pendingmessages then
         send "goSample" to me in 1 millisecond
      end if
   end if
end goSample

on mouseLeave
   put false into sIShouldSample
   put sSamples into field 1
end mouseLeave
... and I get the familiar 8ms (yes, I'm still using the same computer as of old). This may be relevant to your experiment.

Regards,

Michael

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10321
Joined: Wed May 06, 2009 2:28 pm

Re: temporal resolution & screenmouseloc

Post by dunbarx » Wed May 18, 2011 10:32 pm

I wrote a test script. The basic snippet:

Code: Select all

on mouseMove
   put the milliseconds  & return after temp
end mouseMove
I get about 16 ms in the variable temp as a minimum. With the ticks, about one tick. No surprise, but how do you get less?

Craig Newman

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4172
Joined: Sun Jan 07, 2007 9:12 pm

Re: temporal resolution & screenmouseloc

Post by bn » Wed May 18, 2011 10:51 pm

Hi Craig,

use mousewithin if you want to sample more often. But what to sample if the screenMouseloc or the mouseLoc is only updated every 16 milliseconds? That seems to be a system thingy.(?) You might as well use mouseMove.
MouseWithin is depending on the idlerate. You can set that from the default of 500 to lower values.

two fields

script of field 2 (locked, not focusable)

Code: Select all

local sList

on mouseEnter
   set the idlerate to 2
   put "" into sList
end mouseEnter
on mouseWithin
   put the milliseconds & cr after sList
end mouseWithin
on mouseLeave
   put sList into field 1
   set the idlerate to 500
end mouseLeave
Kind regards

Bernd

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10321
Joined: Wed May 06, 2009 2:28 pm

Re: temporal resolution & screenmouseloc

Post by dunbarx » Thu May 19, 2011 5:14 pm

Bernd.

Right, I get several mouseEnter messages sent and handled per millisecond. It was collecting mouse movements that seems to default to the ticks. This cannot be a coincidence.

Craig

Post Reply