Aha, sorry I didn&#39;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">&lt;<a href="mailto:jwmatthys@yahoo.com">jwmatthys@yahoo.com</a>&gt;</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&#39;s not so easy to create a ChucK patch that depends on the mouse&#39;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&#39;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 =&gt; int device;<br>
// get from command line<br>
if( me.args() ) me.arg(0) =&gt; Std.atoi =&gt; device;<br>
<br>
// open mouse 0, exit on fail<br>
if( !hi.openMouse( device ) ) me.exit();<br>
&lt;&lt;&lt; &quot;mouse &#39;&quot; + <a href="http://hi.name" target="_blank">hi.name</a>() + &quot;&#39; ready&quot;, &quot;&quot; &gt;&gt;&gt;;<br>
<br>
int atZero, mouseX, mouseY, screenWidth, screenHeight;<br>
<br>
// prompt user to enter screen size<br>
in.prompt( &quot;enter screen width:&quot; ) =&gt; now;<br>
in.getLine() =&gt; Std.atoi =&gt; screenWidth;<br>
in.prompt( &quot;enter screen height:&quot; ) =&gt; now;<br>
in.getLine() =&gt; Std.atoi =&gt; screenHeight;<br>
in.prompt( &quot;mouse mouse to upper left corner and press enter.&quot;) =&gt; now;<br>
<br>
/* alternative method - calibrate via mouse click<br>
<br>
&lt;&lt;&lt; &quot;Move mouse to upper left corner and click&quot; &gt;&gt;&gt;;<br>
<br>
while (!atZero)<br>
{<br>
 &nbsp; hi =&gt; now;<br>
 &nbsp; while( hi.recv( msg ) )<br>
 &nbsp; {<br>
 &nbsp; &nbsp; &nbsp; if( msg.isButtonDown() )<br>
 &nbsp; &nbsp; &nbsp; {<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 1 =&gt; atZero;<br>
 &nbsp; &nbsp; &nbsp; }<br>
 &nbsp; }<br>
}*/<br>
<br>
// infinite event loop<br>
while( true )<br>
{<br>
 &nbsp; // wait on HidIn as event<br>
 &nbsp; hi =&gt; now;<br>
<br>
 &nbsp; // messages received<br>
 &nbsp; while( hi.recv( msg ) )<br>
 &nbsp; {<br>
 &nbsp; &nbsp; &nbsp; // mouse motion<br>
 &nbsp; &nbsp; &nbsp; if( msg.isMouseMotion() )<br>
 &nbsp; &nbsp; &nbsp; {<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if( msg.deltaX )<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; msg.deltaX +=&gt; mouseX;<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if( msg.deltaY )<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; msg.deltaY +=&gt; mouseY;<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<br>
 &nbsp; &nbsp; &nbsp; }<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // keep values within area of screen<br>
 &nbsp; &nbsp; &nbsp; constrain(mouseX, 0, screenWidth) $ int =&gt; mouseX;<br>
 &nbsp; &nbsp; &nbsp; constrain(mouseY, 0, screenHeight) $ int =&gt; mouseY;<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;&lt;&lt; &quot;Mouse Position:&quot;,mouseX,mouseY&gt;&gt;&gt;;<br>
 &nbsp; }<br>
}<br>
<br>
fun float constrain (float test, float v1, float v2)<br>
{<br>
 &nbsp; Math.min (v1,v2) =&gt; float bottom;<br>
 &nbsp; Math.max (v1,v2) =&gt; float top;<br>
 &nbsp; Math.max (test, bottom) =&gt; test;<br>
 &nbsp; Math.min (test, top) =&gt; test;<br>
 &nbsp; 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&#39;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>