Controlling cursor speed when using a joystick

663 views
Skip to first unread message

Erin

unread,
May 12, 2011, 1:03:51 PM5/12/11
to E-Prime
I want to control the speed the cursor moves when controlling it with
a joystick. I set the joystick to emulate the mouse in my experiment
(inline Joystick.AttachToMouseCursor = True). The joystick is quite
touchy, and causes the cursor to move very quickly across the screen.
For my experiment, I need the cursor to only move slowly, no matter
how much the joystick is moved.

I tried decreasing the mouse sensitivity settings on my computer.
This slowed the cursor down when using the mouse within my experiment,
but had no effect on the joystick. I also tried increasing the
resolution display of my experiment (giving the cursor "further" to
travel)- also no effect. I have also tried adjusting the sensitivity
of my joystick, but the cursor is still too fast.

E-Prime support suggested the following: "E-Prime does have some
limited options for positioning the mouse cursor and limiting its
boundaries. We could try to use a combination of the two to make the
mouse cursor move more slowly. However, this would require significant
scripting and could result in the cursor movement not being smooth"

My main question: Is anyone aware of a simpler way of controlling the
cursor speed in E-Prime?


If not, here is further information on this method:


E-Prime help suggested the following:
"I would recommend taking a look at the MouseDevice.SetCursorLimits
and MouseDevice.SetCursorPos topics in the E-Basic Help (accessed via
the Help menu). The former will allow you to specify boundaries for
the cursor, and the latter will allow you to position the mouse cursor
in a specific area. You could use a combination of the two to first
limit the movement of the cursor so that it does not immediately move
to one edge of the screen, and then use SetCursorPos to move the
cursor move slowly. You could also slowly expand the cursor limits as
the cursor hits the maximum in one direction. This would allow you to
give the appearance of the cursor moving more slowly. To do this, you
would have a loop that continuously checks the cursor position against
the limits that are set, and expand the limits in one direction as the
cursor hits that limit. This would require significant scripting and
could result in the cursor movement not being smooth."

I took a look at the MouseDevice.SetCursorLimits and
MouseDevice.SetCursorPos help, and I understand how this would work in
theory. However, I am very new to programming, and I am afraid that
the scripting involved is a bit over my head. If anyone can offer any
advice or pointers, it would be very appreciated. thank you!

Erin

David McFarlane

unread,
May 12, 2011, 1:58:10 PM5/12/11
to e-p...@googlegroups.com
Erin,

Thanks for posting the full information from PST, that helped (can
you let us know which staff member helped you?). I might have come
up with the Mouse.SetCursorPos approach myself, but not the
Mouse.SetCursorLimits approach, that approach seems a little wacky to
me but what do I know?.

As for Mouse.SetCursorPos, this posed a nice little puzzle, so I
knocked out a quick demo, and here is the inline that I came up
with. (Just to have a mouse click to respond to, I preceded the
inline with a TextDisplay called StimText, set to Duration of 0 and
mouse with Time Limit of (infinite)):


/----------------------------------------------------------------------\
' Code to modify the rate of mouse movement.

Const LoopDelay as Long = 0
Const CursorMoveFactor as Single = 0.5

Dim x0 as Long, y0 as Long
Dim x1 as Long, y1 as Long

Mouse.GetCursorPos x0, y0 ' initialize
Do While (StimText.RT = 0) ' replace this with your exit condition
Mouse.GetCursorPos x1, y1
x0 = x0 + (CursorMoveFactor * (x1 - x0))
y0 = y0 + (CursorMoveFactor * (y1 - y0))
Mouse.SetCursorPos x0, y0
Sleep LoopDelay
Loop
\----------------------------------------------------------------------/


I expected to find some cursor movement artifacts, but it really
worked rather smoothly. As you can see, I didn't even really need
the LoopDelay, but I left it there just in case.

-- David McFarlane, Professional Faultfinder

Erin

unread,
May 12, 2011, 2:46:49 PM5/12/11
to E-Prime
hi David,
Matt was the one helping me.

Thank you very much for the sample code! I tried it out, and it does
change how the cursor moves. For the mouse, it slows it down quite
perfectly. For the joystick, it also slows down, but there is an
interesting effect. The mouse cursor is basically "stuck" to the
joystick. Normally, when you move the joystick left, the cursor
continues to move left, even when the joystick handle is held in a
constant left position. With your modification, the mouse cursor
moves only when you move the joystick. So, the cursor will move left
as you move the joystick left, but when you stop the joystick, it
stops. And, when you let the joystick go back to it's resting
position, the cursor actually backtracks back to it's original
position. This is an interesting feature, but not what will work for
my particular application. (However, I'm sure it's exactly what
someone else might need). It would be absolutely perfect if the
cursor could be "unstuck" from the joystick, so that the joystick
just directs the cursor to move forward in whatever direction the
joystick is pointed. Any suggestions? Again, thank you so much!

Erin

Erin

unread,
May 12, 2011, 2:47:00 PM5/12/11
to E-Prime
hi David,
Matt was the one helping me.

Thank you very much for the sample code! I tried it out, and it does
change how the cursor moves. For the mouse, it slows it down quite
perfectly. For the joystick, it also slows down, but there is an
interesting effect. The mouse cursor is basically "stuck" to the
joystick. Normally, when you move the joystick left, the cursor
continues to move left, even when the joystick handle is held in a
constant left position. With your modification, the mouse cursor
moves only when you move the joystick. So, the cursor will move left
as you move the joystick left, but when you stop the joystick, it
stops. And, when you let the joystick go back to it's resting
position, the cursor actually backtracks back to it's original
position. This is an interesting feature, but not what will work for
my particular application. (However, I'm sure it's exactly what
someone else might need). It would be absolutely perfect if the
cursor could be "unstuck" from the joystick, so that the joystick
just directs the cursor to move forward in whatever direction the
joystick is pointed. Any suggestions? Again, thank you so much!

Erin



On May 12, 1:58 pm, David McFarlane <mcfar...@msu.edu> wrote:

David McFarlane

unread,
May 12, 2011, 3:34:05 PM5/12/11
to e-p...@googlegroups.com
Erin,

Thanks for testing that out, and posting back so quickly. I don't
have any joystick myself, so I don't think I can help any further. I
would not have expected your result, clearly the joystick does not
simply emulate the mouse otherwise it would just work (and in that
case you would not need a code solution in the first place). Is
there a separate Windows "control panel" for the joystick that you
can use to control its settings? Other than that, if it were me I
might try another joystick, or start Googling around for more
technical background on joysticks in general and then use that
knowledge to devise a solution.

Good luck,

David McFarlane

unread,
May 12, 2011, 3:38:17 PM5/12/11
to e-p...@googlegroups.com
Just thinking through this a bit further, if we knew exactly what
data the joystick sent to the PC, and where (e.g., what I/O port)
that data appeared, then in principle we could write code to affect
the cursor in whatever way we wish. But at the moment we lack that
technical information.

-- David McFarlane, Professional Faultfinder

Erin

unread,
May 12, 2011, 8:23:28 PM5/12/11
to E-Prime
Thank you David. I looked up the joystick in the "control panel" and
the only adjustments available are normal calibration, which doesn't
help with adjusting it's sensitivity.

Strange that your code changes the behavior of the joystick within E-
Prime. In effect, it changes the joystick's effect on the cursor, and
makes it function more like a track ball. E-Prime must treat the
joystick input differently than the mouse input, and your code somehow
interacts with that difference.

I am not sure exactly what data the joystick sends to the PC or in
what I/O port the date appears. I'll do some more research, and post
back here if I find anything that may be useful. Thank you again so
much for your help!

Erin

Michiel Spape

unread,
May 13, 2011, 4:34:03 AM5/13/11
to e-p...@googlegroups.com
Hiya,
Two points here:
- For one, I'd suggest just going a bit higher into Windows and setting the mouse and/or joystick sensitivity. I remember this was quite common in Win98 or something like that, but it seems to be missing in Windows XP. Nevertheless, I very much doubt you won't be able to find a little programme that sets the cursor and/or mouse sensitivity to a lower resolution. All in all, that would be a lot easier for your purposes.
- Second, it seems to me that the main issue with joystick vs mouse is the joystick being centred at a certain position. I think - but could be mistaken? - that in order to do this, you might want to change the script so that the X0, Y0 are not overwritten, but rather that you change the cursor position by the deviation with the beginning of the trial. So, if the cursor is at pixel 320,240 in the beginning (i.e. centre at 640x480 resolution), then at next polling the cursor is at 321,240 (1 pixel to the right), the cursor should (as it does currently) move one pixel to the right. However, at the polling after that, given that the subject didn't move the joystick (i.e. polling says it's the same as previous polling), then the difference of 1,0 related to the *startposition* should still cause it to move 1 more to the right (i.e. 322,240). I'm terrible at messing with someone else's code, but if you understand what I'm saying, this shouldn't be too hard to implement (just keep comparing to the start position, rather than the previous position). More hardcore, by the way, and likely better (given that most joysticks tend to be round, rather than square) would be to calculate the angle and amplitude of the joystick, then move the cursor with that information.

Hope that helps,
Mich


Michiel Spapé
Research Fellow
Perception & Action group
University of Nottingham
School of Psychology
www.cognitology.eu

--
You received this message because you are subscribed to the Google Groups "E-Prime" group.
To post to this group, send email to e-p...@googlegroups.com.
To unsubscribe from this group, send email to e-prime+u...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/e-prime?hl=en.

This message and any attachment are intended solely for the addressee and may contain confidential information. If you have received this message in error, please send it back to me, and immediately delete it. Please do not use, copy or disclose the information contained in this message or in any attachment. Any views or opinions expressed by the author of this email do not necessarily reflect the views of the University of Nottingham.

This message has been checked for viruses but the contents of an attachment
may still contain software viruses which could damage your computer system:
you are advised to perform your own checks. Email communications with the
University of Nottingham may be monitored as permitted by UK legislation.

Erin

unread,
May 13, 2011, 4:06:56 PM5/13/11
to E-Prime
Thank you for the pointers.

I had already tried slowing down the cursor speed in windows. This
successfully slows down the mouse cursor speed within E-Prime, but has
no effect on the joystick. There are not similar controls for
joystick sensitivity in the game controller section of the Windows
control panel.

So, I did more testing of the joystick in E-Prime. Turns out, the
cursor is "stuck" to the joystick even without David's code. His code
just slowed down the cursor enough that the effect was much more
noticeable. Before, the cursor was so sensitive that only very small
joystick moments were needed to move the cursor and make an image
selection, and the "backtracking" behavior was less apparent. (The
experiment is set up to re-center the cursor on every trial, also
making it less obvious). So, when the cursor speed is slowed, the
range of the cursor is very diminished when using the joystick- you
can't even reach the edge of the screen with the cursor (which is
obviously a problem).

Anyone have any ideas of how to make the joystick only "push" the
cursor forward in E-Prime, and not "pull" it back when the joystick is
moved back towards center?

Erin




On May 13, 4:34 am, Michiel Spape <Michiel.Sp...@nottingham.ac.uk>
wrote:
> For more options, visit this group athttp://groups.google.com/group/e-prime?hl=en.
>
> This message and any attachment are intended solely for the addressee and may contain confidential information. If you have received this message in error, please send it back to me, and immediately delete it.   Please do not use, copy or disclose the information contained in this message or in any attachment.  Any views or opinions expressed by the author of this email do not necessarily reflect the views of the University of Nottingham.
>
> This message has been checked for viruses but the contents of an attachment
> may still contain software viruses which could damage your computer system:
> you are advised to perform your own
>
> ...
>
> read more »

David McFarlane

unread,
May 16, 2011, 2:35:30 PM5/16/11
to e-p...@googlegroups.com
Erin,

Well, I was mighty puzzled when it seemed that my
code made the joystick behave oddly, so I am glad
that you took the trouble to test it further and
report back that the joystick always behaves that way, thanks.

But that doesn't help you solve your problem. It
does seem odd to me that the joystick behaves
that way, it seems to me that if that behavior
were common then other E-Prime users would have
made a note of it. So I hope we hear from other
E-Prime users with joysticks about whether as a
rule the screen cursor simply mirrors the current
joystick position, or if instead the cursor
continues moving as long as the joystick is
pushed off-center. If joysticks for other users
work in the "unstuck" way, then I would suspect
the problem has something to do with your
particular joystick and you might want to try
another. To that end, you might ask PST support
again what joysticks they recommend.

BTW, just for kicks I started to make a second
demo to follow Matt Lenhart's suggestion to use
SetCursorLimits. But I don't see how that could
possibly work. If cursor limits are set to the
current cursor position, then any attempt to move
the cursor any farther from center will result in
no movement at all, so there will be no new
cursor data with which to set new cursor
limits. E.g., suppose the cursor is at (100,
100), so you set one corner of the cursor limit
to (100, 100). The subject then moves such that
the cursor should move to, say, (90,90). But
that is beyond the current limit, so the cursor
stays at (100, 100), and the system lacks any
information regarding the subject's attempt to
move the cursor and so the cursor just stays
where it is. (Of course, it would still detect
inward movements, but that hardly helps you.) So I gave up on that idea.

So I am afraid that I am out of ideas.

-- David McFarlane, Professional Faultfinder

Michiel Spape

unread,
May 17, 2011, 6:38:10 AM5/17/11
to e-p...@googlegroups.com
Hi Erin and David,
First thing: when I suggested looking around for a programme that could adjust the joystick sensitivity, I did not only mean windows settings in control pad. What kind of joystick are we talking about? A number of them come with native (but not necessarily required) applications that adjust sensitivity, and there are bound to be third-party programmes out there that do it for you, courtesy of the numerous coding gamers. I'd suggest not immediately giving up after having looked at the control panel.

Second, I was wondering whether my suggestion of extracting angle and amplitude from joystick manoeuvres was understood. As joysticks tend to have a round interface, rather than (like a screen) a rectangular one, it is useful to remember that, in essence, a cursor position in joy-stick terms, of 0,0 (upper left corner) in one stroke, should not be possible. For this reason, as well as for the essential other differences with mice, I think it makes much less sense than one might first think to let the joystick have anything to do with a mouse. If memory serves, the new E-Prime (perhaps even the old one), comes with the possibility of extracting joystick data independent from mouse, and I think it makes a lot of sense to only /set/ the mouse cursor position (i.e. a mere graphic), rather than in any way /get/ it. One thus ought to move it by using angle and amplitude (this requires some basic trigonometry which I generally have to look up again and again), or merely angle, if you have a more classic one.

So:


"Anyone have any ideas of how to make the joystick only "push" the cursor forward in E-Prime, and not "pull" it back when the joystick is moved back towards center?"

Well, if (previous amplitude > current amplitude) then move, otherwise don't. Sorry, I had a more articulate suggestion here, based on David's code below, but I'll leave that for another day, if you don't mind.
Best,
Mich

Erin

For more options, visit this group at http://groups.google.com/group/e-prime?hl=en.

This message and any attachment are intended solely for the addressee and may contain confidential information. If you have received this message in error, please send it back to me, and immediately delete it. Please do not use, copy or disclose the information contained in this message or in any attachment. Any views or opinions expressed by the author of this email do not necessarily reflect the views of the University of Nottingham.

This message has been checked for viruses but the contents of an attachment
may still contain software viruses which could damage your computer system:

Reply all
Reply to author
Forward
0 new messages