Hi everyone,
I still can't get the point about how to catch a Ctrl+Enter in a
wx.TextCtrl in msw.
I'm trying to process it on a wx. EVT_CHAR.
As said here:
Another kind of translation is done when the control key is pressed: for example, for CTRL-A key press the key down event still carries the same key code
'A' as usual but the char event will have key code of 1, the ASCII value of this key combination.
I understand that I need to make a transformation to get the
Ctrl+Enter keycode. For letters it's quite easy, but not for the Enter
key.
Any ideas are greatly appreciated.
Thanks!
···
--
With best regards from Ukraine,
Andre
Skype: Francophile
Twitter: @m_elensule; Facebook: menelion
My blog: http://menelion.oire.org/
Hi Andre,
Hi everyone,
I still can’t get the point about how to catch a Ctrl+Enter in a
wx.TextCtrl in msw.
I’m trying to process it on a wx. EVT_CHAR.
As said here:
Another kind of translation is done when the control key is pressed: for example, for CTRL-A key press the key down event still carries the same key code
‘A’ as usual but the char event will have key code of 1, the ASCII value of this key combination.
I understand that I need to make a transformation to get the
Ctrl+Enter keycode. For letters it’s quite easy, but not for the Enter
key.
Any ideas are greatly appreciated.
Thanks!
–
With best regards from Ukraine,
Andre
I’m not sure if you can. However, you can definitely catch the enter key itself if you set its style flag:
style=wx.TE_PROCESS_ENTER
So something like this:
mytext = wx.TextCtrl(panel, style=wx.TE_PROCESS_ENTER)
This might allow you to catch CTRL+ENTER as well, although I'm not sure.
- Mike
···
On Friday, December 12, 2014 7:41:17 AM UTC-6, Andre Polykanine wrote:
Hello Mike,
Actually, I would like to do something like is done in Skype:
a check box in the configuration determines whether a message should
be sent using Enter or Ctrl+Enter. If "Send messages with Enter key"
is checked, Ctrl+Enter should insert a line break, and Enter should
send the message. If not, it should be vice versa: Enter inserts a
line break, and Ctrl+Enter sends a message.
Everything works as expected only if the box is not checked: Enter
inserts a line break and Ctrl+Enter sends a message. But if the box is
checked, both send the message, so I'm unable to make Ctrl+Enter
insert a line break and not submit the dialog.
Thanks a lot!
···
--
With best regards from Ukraine,
Andre
Skype: Francophile
Twitter: @m_elensule; Facebook: menelion
My blog: http://menelion.oire.org/
------------ Original message ------------
From: Mike Driscoll <kyosohma@gmail.com>
To: wxpython-users@googlegroups.com
Date created: , 4:01:34 PM
Subject: [wxPython-users] Re: Action on Ctrl+Enter in wx.TextCtrl in msw
Hi Andre,
On Friday, December 12, 2014 7:41:17 AM UTC-6, Andre Polykanine wrote:
Hi everyone,
I still can't get the point about how to catch a Ctrl+Enter in a
wx.TextCtrl in msw.
I'm trying to process it on a wx. EVT_CHAR.
As said here:
> Another kind of translation is done when the control key is pressed: for
example, for CTRL-A key press the key down event still carries the same key
code
> 'A' as usual but the char event will have key code of 1, the ASCII value
of this key combination.
I understand that I need to make a transformation to get the
Ctrl+Enter keycode. For letters it's quite easy, but not for the Enter
key.
Any ideas are greatly appreciated.
Thanks!
--
With best regards from Ukraine,
Andre
I'm not sure if you can. However, you can definitely catch the enter key
itself if you set its style flag:
style=wx.TE_PROCESS_ENTER
So something like this:
mytext = wx.TextCtrl(panel, style=wx.TE_PROCESS_ENTER)
This might allow you to catch CTRL+ENTER as well, although I'm not sure.
- Mike
--
You received this message because you are subscribed to the Google Groups "wxPython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to wxpython-users+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Andre Polykanine wrote:
Hi everyone,
I still can't get the point about how to catch a Ctrl+Enter in a
wx.TextCtrl in msw.
I'm trying to process it on a wx. EVT_CHAR.
...
I understand that I need to make a transformation to get the
Ctrl+Enter keycode. For letters it's quite easy, but not for the Enter
key.
Sure it is. A few minutes of experimentation with they KeyEvents.py
demo would have told you this.
The Enter key is delivered to EVT_CHAR as WXK_RETURN, which has a value
of 13, which is the ASCII value of Ctrl-M, or Carriage Return.
On Windows, at least, Ctrl-Enter is delivered to EVT_CHAR as Ctrl-J,
which has an ASCII numeric value of 10. This is ASCII Linefeed, which
Unix called "new line".
You can also use '\r' for Enter and '\n' for Ctrl-Enter.
···
--
Tim Roberts, timr@probo.com
Providenza & Boekelheide, Inc.
Be aware that if you provide the wx.TE_RICH2 style flag to your wx.TextCtrl, and possibly wx.TE_RICH, although I haven’t tested that one, that those flags will add additional accelerators including CTRL+ENTER and SHIFT+ENTER. One is a paragraph insert the other a page insert I believe. In these cases handling CTRL or SHIFT + ENTER will be handled in the EVT_KEY_DOWN event by the wx.TextCtrl before the EVT_CHAT event is fired.
To preempt the wx.TextCtrl from processing those key down events handle the EVT_KEY_DOWN yourself perhaps like so:
def OnKeyDown(self, event):
keycode = event.GetKeyCode ( )
controlDown = event.CmdDown ( )
altDown = event.AltDown ( )
shiftDown = event.ShiftDown ( )
if keycode == wx.WXK_RETURN:
if (userSettings.CtrlEnter.ischecked() and controlDown) or
(not userSettings.CtrlEnter.ischecked() and not controlDown):
doStuff()
return # eat keystroke
# pass all other keys
event.Skip()
``
works nicely. “userSettings.CtrlEnter.ischecked()” is some arbitrary flag that represents your menu toggle for what CTRL+ENTER does.