[Gtk-sharp-list] Subclassing a textview cannot control ControlMask key event
m.j.hutchinson at gmail.com
Mon Aug 25 13:39:27 EDT 2008
On Mon, Aug 25, 2008 at 5:26 AM, True Friend <true.friend2004 at gmail.com> wrote:
> I am trying to subclass a textview to write custom characters. Here is the
> sample code which I am using in "protected override OnKeyPress(EventArgs
> evnt)" method in derived class.
> protected override bool OnKeyPressEvent (EventKey evnt)
> Dictionary<char, char> dict = new Dictionary<char,char>();
> dict['`'] = 'ٍ';
> dict['1'] = '1';
> dict['2'] = '2';
> dict['3'] = '3';
> dict['4'] = '4';
> if(evnt.State != ModifierType.ControlMask)
> char key = (char)evnt.Key;
> this.Editable = false;
> this.Editable = true;
> return base.OnKeyPressEvent (evnt);
> I want to write only when Ctrl key is not pressed when it is pressed the
> event should be the default one, I've tried to do so but evnt.State !=
> ModifierType.ControlMask is not working. The output on console.Writeline is
> also given here. Normal key press is Mod2Mask but ctrl key press plus any
> other key press is ControlMask, Mod2Mask two in same line are written.
> Interesting is this it is accepting ControlMask (input) but allowing to
> write the key as well (the hacked evenet handler is processed even).
> Any ideas about it? I am missing something or something else involved here?
ModifierType is a "Flags" enum.
for some explanation)
Hence, use a bitwise "and" to check whether the ControlMask flag is
set on State; if the result is zero, the bit corresponding to
ControlMask is not set.
((evnt.State & ModifierType.ControlMask) == 0)
More information about the Gtk-sharp-list