I need custom code to reverse the direction of the mouse/cursor in a block or question. That is, when a participant taking the survey moves their cursor up, it goes down, when they move right, it moves left, etc. The cursor should move in the opposite or mirrored direction from the participant's mouse movement.
Any help at all would be greatly appreciated!
Found the below code online. Not sure if it will work, but I can't get it to run in Qualtrics. I keep getting "Unexpected token class" error.
internal class Inverter
{
private Point pos = Cursor.Position;
private bool invertX;
private bool invertY;
private bool running;
private bool exit;
public bool InvertX
{
get
{
return this.invertX;
}
set
{
this.invertX = value;
if (this.InvertSettingsChanged != null)
{
this.InvertSettingsChanged(this, new EventArgs());
}
}
}
public bool InvertY
{
get
{
return this.invertY;
}
set
{
this.invertY = value;
if (this.InvertSettingsChanged != null)
{
this.InvertSettingsChanged(this, new EventArgs());
}
}
}
public bool Running
{
get
{
return this.running;
}
}
public Inverter(bool x, bool y)
{
this.invertX = x;
this.invertY = y;
this.pos = Cursor.Position;
}
private void MouseLoop()
{
Thread.CurrentThread.IsBackground = true;
Thread.CurrentThread.Priority = ThreadPriority.Highest;
while (!this.exit)
{
Point position = Cursor.Position;
int right = (this.invertX ? this.pos.X - (position.X - this.pos.X) : position.X);
if (this.invertX)
{
if (right < 2)
{
right = 2;
}
if (right > Screen.FromPoint(position).Bounds.Right - 2)
{
Rectangle bounds = Screen.FromPoint(position).Bounds;
right = bounds.Right - 2;
}
}
int bottom = (this.invertY ? this.pos.Y - (position.Y - this.pos.Y) : position.Y);
if (this.invertY)
{
if (bottom < 2)
{
bottom = 2;
}
if (bottom > Screen.FromPoint(position).Bounds.Bottom - 2)
{
Rectangle rectangle = Screen.FromPoint(position).Bounds;
bottom = rectangle.Bottom - 2;
}
}
Cursor.Position = new Point(right, bottom);
this.pos = Cursor.Position;
Thread.Sleep(1);
}
this.exit = false;
}
public void Start()
{
this.pos = Cursor.Position;
this.running = true;
(new Thread(new ThreadStart(this.MouseLoop))).Start();
}
public void Stop()
{
this.running = false;
this.exit = true;
}
public event EventHandler InvertSettingsChanged;
}
Leave a Reply
Enter your E-mail address. We'll send you an e-mail with instructions to reset your password.