Hi, Is it possible to change the data from an event, SEL_KEYPRESS or SEL_KEYRELEASE or the like, in order to, say, randomly change the codes of each keystroke? If it is, how could I achieve this? I''ve tried this: text = FXTextField.new(self, 20) text.connect(SEL_KEYPRESS, method(:changeText)) ... def changeText(sender, selector, data) A = ''A''.sum 0 Z = ''Z''.sum 0 a = ''a''.sum 0 z = ''z''.sum 0 c = data.code case c when A .. Z c = rand(25) + A when a .. z c = rand(25) + a end if c != data.code data.code = c end false end But it doesn''t work, and if I type in "hello", that''s exactly what I see in the control. So, again, is it possible to change that data? Thank you, -- angico ------ home page: www.angico.org Gnu/Linux, FLOSS, Espiritismo, e eu por mim mesmo 8^I ------ contatos: email: angico at angico.org skype: angico00 ------
Jeroen van der Zijp
2008-Aug-27 02:17 UTC
[fxruby-users] changing FXTextField default behavior
On Tuesday 26 August 2008, angico wrote:> Hi, > > Is it possible to change the data from an event, SEL_KEYPRESS or > SEL_KEYRELEASE or the like, in order to, say, randomly change the codes > of each keystroke? > > If it is, how could I achieve this? > > I''ve tried this: > > text = FXTextField.new(self, 20) > text.connect(SEL_KEYPRESS, method(:changeText)) > ... > def changeText(sender, selector, data) > A = ''A''.sum 0 > Z = ''Z''.sum 0 > a = ''a''.sum 0 > z = ''z''.sum 0 > > c = data.code > > case c > when A .. Z > c = rand(25) + A > when a .. z > c = rand(25) + a > end > > if c != data.code > data.code = c > end > > false > end > > But it doesn''t work, and if I type in "hello", that''s exactly what I see > in the control. > > So, again, is it possible to change that data?When you intercept SEL_KEYPRESS, the keysym is passed to FXEvent.code and the translated text is in FXEvent.text. If the .code represents an editing command, the .text member is disregarded; but if the .code is a regular character, the string which is the translation of the [sequence of] keysyms is inserted. This way, input methods can be used to insert text while regular editing commands still work normally. - Jeroen -- +----------------------------------------------------------------------------+ | Copyright (C) 21:10 08/26/2008 Jeroen van der Zijp. All Rights Reserved. | +----------------------------------------------------------------------------+