# Evt\_key\_down() { | event | }

**URL:** <https://www.ruby-forum.com/t/evt-key-down-event/203984>\
**Category:** wxRuby\
**Created:** [March 2, 2011, 10:22pm UTC](https://www.ruby-forum.com/t/evt-key-down-event/203984 "2011-03-02T22:22:41Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![dubstep](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/cdc98d/32.png) [@dubstep](https://www.ruby-forum.com/u/dubstep)\
**Post date:** [March 2, 2011, 10:22pm UTC](https://www.ruby-forum.com/t/evt-key-down-event/203984/1 "2011-03-02T22:22:41Z")

</div>

Bonsoir Alex.  
J’ai un problème avec “evt\_key\_down() { | event | … }”.  
Je m’explique:  
Quand j’ouvre mon application, “evt\_key\_down() { | event | … }”  
fonctionne correctement, mais à partir du moment que je fait un clique  
avec la souris sur TextCtrl par exemple, “evt\_key\_down() { | event | …  
}” ce désactive et ne fonctionne plus.  
Que faut-il que je fasse pour que “evt\_key\_down() { | event | … }”  
reste activé?  
merci.

---

<div class="post-metadata">

**Author:** ![SSSSSbastienSS\_SSS](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/c89c15/32.png) [@SSSSSbastienSS\_SSS](https://www.ruby-forum.com/u/SSSSSbastienSS_SSS)\
**Post date:** [March 3, 2011, 1:29am UTC](https://www.ruby-forum.com/t/evt-key-down-event/203984/2 "2011-03-03T01:29:41Z")

</div>

Bonjour Sbastien,

Le problme que vous rencontrez, est d au fait que evt\_key\_down () {|  
vnement | …} est li l’instance que votre question lorsque vous  
l’invoquez. En d’autres termes, evt\_key\_down () est fix en fonction de  
votre fentre / cadre, pas le TextCtrl. Le TextCtrl a son propre systme  
de  
touche de gestion, qui est contrle en interne par la bibliothque  
wxWidgets. Afin de saisir le texte entr dans un TextCtrl, vous devez  
utiliser evt\_text () {| vnement | …} afin de capturer le texte saisi  
dans un TextCtrl. Si vous voulez capturer des vnements Tab ainsi, vous  
devrez ajouter le Wx:: drapeau TE\_PROCESS\_TAB la cration de votre  
TextCtrl. Mme avec le traitement d’un retour, vous devez utiliser Wx::  
TE\_PROCESS\_ENTER pour capturer le retour aussi.Mais pour le traitement  
de  
Wx:: TE\_PROCESS\_ENTER, vous devez utiliser la evt\_text\_enter () {|  
vnement  
| …} pour le processus.

((  
Hello Sebastian,  
The problem you are having, is due to the fact that evt\_key\_down()  
{|event|  
…} is bound to the instance that your dealing with when you invoke it.  
In  
other words, evt\_key\_down() is being set on your Window / Frame, not the  
TextCtrl. The TextCtrl has it’s own Key Handling system, that is  
controlled  
internally by the wxWidgets library. In order to capture text entered  
in a  
TextCtrl, you need to use evt\_text() {|event| …} in order to capture  
text  
entered in a TextCtrl. If you want to capture Tab Events as well, you  
will  
need to add the Wx::TE\_PROCESS\_TAB flag to the creation of your  
TextCtrl.  
Same with processing a Return, you need to use Wx::TE\_PROCESS\_ENTER to  
capture the return as well. But for processing Wx::TE\_PROCESS\_ENTER,  
you  
need to use the evt\_text\_enter() {|event| …} to process it.  
hth,  
Mario  
))  
2011/3/2 Sbastien [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

> Bonsoir Alex.  
> J’ai un problme avec “evt\_key\_down() { | event | … }”.  
> Je m’explique:  
> Quand j’ouvre mon application, “evt\_key\_down() { | event | … }”  
> fonctionne correctement, mais partir du moment que je fait un clique  
> avec  
> la souris sur TextCtrl par exemple, “evt\_key\_down() { | event | … }”  
> ce  
> dsactive et ne fonctionne plus.  
> Que faut-il que je fasse pour que “evt\_key\_down() { | event | … }” reste  
> activ?  
> merci.
> 
> * * *
> 
> wxruby-users mailing list  
> [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
> [http://rubyforge.org/mailman/listinfo/wxruby-users](http://rubyforge.org/mailman/listinfo/wxruby-users)

((  
Good evening Alex.  
I have a problem with “evt\_key\_down () {| event | …}”.  
Let me explain:  
When I open my application, “evt\_key\_down () {| event | …}” works  
fine,  
but from the time I made a mouse click on TextCtrl for example,  
"evt\_key\_down () {| event |. ..} "this off and no longer works.  
What should I do to that “evt\_key\_down () {| event | …}” is enabled?  
thank you.  
))

–  
Mario S.  
Lieutenant Commander 3  
XO - Geo 99  
XO - STO IFT Fleet

> **[HOME | The Federation](https://www.trekfederation.com)**

[http://geo99.ruby-im.net](http://geo99.ruby-im.net)
