<div>It sounds like you&#39;re hooking the KeyPress event instead of the KeyDown event. That&#39;s why you get a KeyChar instead of a KeyCode and it also might be why the code isn&#39;t working as you expect.</div><div><br>
</div>I can get the Keys enumeration just fine:<div><br></div><div><div>IronPython 2.6 Beta 1 DEBUG (2.6.0.10) on .NET 2.0.50727.3053</div><div>Type &quot;help&quot;, &quot;copyright&quot;, &quot;credits&quot; or &quot;license&quot; for more information.</div>
<div>&gt;&gt;&gt; import clr</div><div>&gt;&gt;&gt; clr.AddReference(&#39;System.Windows.Forms&#39;)</div><div>&gt;&gt;&gt; from System.Windows.Forms import Keys</div><div>&gt;&gt;&gt; Keys.Enter</div><div>&lt;System.Windows.Forms.Keys object at 0x000000000000002B [Return]&gt;</div>
<div>&gt;&gt;&gt;</div><div><br></div><div><br></div><br><div class="gmail_quote">On Thu, Jul 9, 2009 at 1:32 PM, Summer_Intern <span dir="ltr">&lt;<a href="mailto:itssivaguru@gmail.com">itssivaguru@gmail.com</a>&gt;</span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;"><br>
Hello,<br>
<br>
Thanks for the Suggestion . I set the &#39;AcceptsReturn = True&#39; for the<br>
textbox.<br>
But the problem I found is that its not able to recognize the &#39;Enter&#39;key<br>
press .<br>
<br>
Here is the Code :<br>
<br>
        def OnKeyPress(self,sender,args):<br>
                print (args.KeyChar)<br>
                if(args.KeyChar == Keys.Return):<br>
                        print &#39;Enter Key Pressed&#39;<br>
<br>
1) I tried args.KeyCode . It returned an exception<br>
2) I tried if(args.KeyChar == Keys. Enter) , the if condition is not passing<br>
when I press the Enter Key . Where as a new line is printed on the console.<br>
3) Same behavior when I have if(args.KeyChar == Keys.Return):<br>
<br>
I think its not able to understand the enum &#39;Keys&#39;.<br>
I also tried doing &#39;from System.Windows.Forms import Keys&#39;. but still no<br>
good .<br>
<br>
Any idea whats missing or incorrect ?<br>
<br>
Thanks !<br>
<br>
briancurtin wrote:<br>
&gt;<br>
&gt; On Wed, Jul 1, 2009 at 09:31, Sivaguru Perambalam<br>
&gt; &lt;<a href="mailto:itssivaguru@gmail.com">itssivaguru@gmail.com</a>&gt;wrote:<br>
&gt;<br>
&gt;&gt; Hello ,<br>
&gt;&gt;<br>
&gt;&gt; I have a Windows form with a text box and a button.<br>
&gt;&gt; What I want to implement it, when the user hits the &#39;Enter&#39; key in the<br>
&gt;&gt; text<br>
&gt;&gt; box, the function that&#39;s linked to the ButtonClick event has to be<br>
&gt;&gt; invoked.<br>
&gt;&gt; Please give me like a code example of how this could be done in a simpler<br>
&gt;&gt; way, since I am not familiar with Forms or GUI stuff .<br>
&gt;&gt;<br>
&gt;&gt; Thanks !<br>
&gt;&gt;<br>
&gt;<br>
&gt; You could check out the OnKeyDown event:<br>
&gt; <a href="http://msdn.microsoft.com/en-us/library/system.windows.forms.control.onkeydown(loband).aspx" target="_blank">http://msdn.microsoft.com/en-us/library/system.windows.forms.control.onkeydown(loband).aspx</a>.<br>

&gt; The C# example pretty easily translates to IronPython, so you could follow<br>
&gt; that and check when the KeyEventArgs.KeyCode is equal to Keys.Return, then<br>
&gt; call your ButtonClick method.<br>
&gt;<br>
&gt; _______________________________________________<br>
&gt; Users mailing list<br>
&gt; <a href="mailto:Users@lists.ironpython.com">Users@lists.ironpython.com</a><br>
&gt; <a href="http://lists.ironpython.com/listinfo.cgi/users-ironpython.com" target="_blank">http://lists.ironpython.com/listinfo.cgi/users-ironpython.com</a><br>
&gt;<br>
&gt;<br>
<font color="#888888"><br>
--<br>
View this message in context: <a href="http://www.nabble.com/How-to-capture-a-%27Carriage-Return%27-in-a-windows-form---tp24290861p24417356.html" target="_blank">http://www.nabble.com/How-to-capture-a-%27Carriage-Return%27-in-a-windows-form---tp24290861p24417356.html</a><br>

Sent from the IronPython mailing list archive at Nabble.com.<br>
<br>
_______________________________________________<br>
Users mailing list<br>
<a href="mailto:Users@lists.ironpython.com">Users@lists.ironpython.com</a><br>
<a href="http://lists.ironpython.com/listinfo.cgi/users-ironpython.com" target="_blank">http://lists.ironpython.com/listinfo.cgi/users-ironpython.com</a><br>
</font></blockquote></div><br></div>