Aha, sorry I didn't realise that you meant the pointer on the screen.<br><br>/Stefan<br><br><div class="gmail_quote">On Thu, Oct 23, 2008 at 10:05 AM, Joel Matthys <span dir="ltr"><<a href="mailto:jwmatthys@yahoo.com">jwmatthys@yahoo.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">Actually, this is an interesting question. Hid tracks mouse motion rather than mouse position, so it's not so easy to create a ChucK patch that depends on the mouse's position on the screen. (ie trigger a sound when the mouse is in the upper left hand corner.)<br>
<br>
I modified the <a href="http://mouse.ck" target="_blank">mouse.ck</a> example below. It prompts you to enter the screen size (one could easily set this up as an argument; is there any way for ChucK to access this property without user input?) and calibrates the mouse position from the upper left hand corner.<br>
<br>
This works fine if I move the mouse slowly, but it's not absolutely correlative to the pointer position on the screen. Any suggestions on how to refine this?<br>
<br>
Joel<br>
<br>
Chuck code follows:<br>
<br>
// <a href="http://mouse-pos.ck" target="_blank">mouse-pos.ck</a><br>
<br>
// make HidIn and HidMsg<br>
Hid hi;<br>
HidMsg msg;<br>
// make ConsoleInput<br>
ConsoleInput in;<br>
<br>
// which mouse<br>
0 => int device;<br>
// get from command line<br>
if( me.args() ) me.arg(0) => Std.atoi => device;<br>
<br>
// open mouse 0, exit on fail<br>
if( !hi.openMouse( device ) ) me.exit();<br>
<<< "mouse '" + <a href="http://hi.name" target="_blank">hi.name</a>() + "' ready", "" >>>;<br>
<br>
int atZero, mouseX, mouseY, screenWidth, screenHeight;<br>
<br>
// prompt user to enter screen size<br>
in.prompt( "enter screen width:" ) => now;<br>
in.getLine() => Std.atoi => screenWidth;<br>
in.prompt( "enter screen height:" ) => now;<br>
in.getLine() => Std.atoi => screenHeight;<br>
in.prompt( "mouse mouse to upper left corner and press enter.") => now;<br>
<br>
/* alternative method - calibrate via mouse click<br>
<br>
<<< "Move mouse to upper left corner and click" >>>;<br>
<br>
while (!atZero)<br>
{<br>
hi => now;<br>
while( hi.recv( msg ) )<br>
{<br>
if( msg.isButtonDown() )<br>
{<br>
1 => atZero;<br>
}<br>
}<br>
}*/<br>
<br>
// infinite event loop<br>
while( true )<br>
{<br>
// wait on HidIn as event<br>
hi => now;<br>
<br>
// messages received<br>
while( hi.recv( msg ) )<br>
{<br>
// mouse motion<br>
if( msg.isMouseMotion() )<br>
{<br>
if( msg.deltaX )<br>
{<br>
msg.deltaX +=> mouseX;<br>
}<br>
if( msg.deltaY )<br>
{<br>
msg.deltaY +=> mouseY;<br>
}<br>
}<br>
// keep values within area of screen<br>
constrain(mouseX, 0, screenWidth) $ int => mouseX;<br>
constrain(mouseY, 0, screenHeight) $ int => mouseY;<br>
<<< "Mouse Position:",mouseX,mouseY>>>;<br>
}<br>
}<br>
<br>
fun float constrain (float test, float v1, float v2)<br>
{<br>
Math.min (v1,v2) => float bottom;<br>
Math.max (v1,v2) => float top;<br>
Math.max (test, bottom) => test;<br>
Math.min (test, top) => test;<br>
return test;<br>
}<br>
<br>
// end of <a href="http://mouse-pos.ck" target="_blank">mouse-pos.ck</a><div><div></div><div class="Wj3C7c"><br>
<br>
eduard aylon wrote:<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
Hello list,<br>
<br>
is there a way to track y-position of the mouse pointer. It's not in the manual.<br>
I know I can track the x-position with HidMsg.fdata<br>
<br>
thanks,<br>
<br>
eduard<br>
_______________________________________________<br>
chuck-users mailing list<br>
<a href="mailto:chuck-users@lists.cs.princeton.edu" target="_blank">chuck-users@lists.cs.princeton.edu</a><br>
<a href="https://lists.cs.princeton.edu/mailman/listinfo/chuck-users" target="_blank">https://lists.cs.princeton.edu/mailman/listinfo/chuck-users</a><br>
<br>
</blockquote>
<br>
<br>
_______________________________________________<br>
chuck-users mailing list<br>
<a href="mailto:chuck-users@lists.cs.princeton.edu" target="_blank">chuck-users@lists.cs.princeton.edu</a><br>
<a href="https://lists.cs.princeton.edu/mailman/listinfo/chuck-users" target="_blank">https://lists.cs.princeton.edu/mailman/listinfo/chuck-users</a><br>
</div></div></blockquote></div><br><br clear="all"><br>-- <br>Release me, insect, or I will destroy the Cosmos!<br>