<div>It sounds like you're hooking the KeyPress event instead of the KeyDown event. That's why you get a KeyChar instead of a KeyCode and it also might be why the code isn'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 "help", "copyright", "credits" or "license" for more information.</div>
<div>>>> import clr</div><div>>>> clr.AddReference('System.Windows.Forms')</div><div>>>> from System.Windows.Forms import Keys</div><div>>>> Keys.Enter</div><div><System.Windows.Forms.Keys object at 0x000000000000002B [Return]></div>
<div>>>></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"><<a href="mailto:itssivaguru@gmail.com">itssivaguru@gmail.com</a>></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 'AcceptsReturn = True' for the<br>
textbox.<br>
But the problem I found is that its not able to recognize the 'Enter'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 'Enter Key Pressed'<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 'Keys'.<br>
I also tried doing 'from System.Windows.Forms import Keys'. but still no<br>
good .<br>
<br>
Any idea whats missing or incorrect ?<br>
<br>
Thanks !<br>
<br>
briancurtin wrote:<br>
><br>
> On Wed, Jul 1, 2009 at 09:31, Sivaguru Perambalam<br>
> <<a href="mailto:itssivaguru@gmail.com">itssivaguru@gmail.com</a>>wrote:<br>
><br>
>> Hello ,<br>
>><br>
>> I have a Windows form with a text box and a button.<br>
>> What I want to implement it, when the user hits the 'Enter' key in the<br>
>> text<br>
>> box, the function that's linked to the ButtonClick event has to be<br>
>> invoked.<br>
>> Please give me like a code example of how this could be done in a simpler<br>
>> way, since I am not familiar with Forms or GUI stuff .<br>
>><br>
>> Thanks !<br>
>><br>
><br>
> You could check out the OnKeyDown event:<br>
> <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>
> The C# example pretty easily translates to IronPython, so you could follow<br>
> that and check when the KeyEventArgs.KeyCode is equal to Keys.Return, then<br>
> call your ButtonClick method.<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>
><br>
><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>