On Mon, Aug 25, 2008 at 5:26 AM, True Friend <[EMAIL PROTECTED]> wrote: > Hi > 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; > if(dict.ContainsKey(key)) > { > this.Buffer.InsertInteractiveAtCursor(dict[key].ToString(), > true); > } > else > { > 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. (see http://msdn.microsoft.com/en-us/library/system.flagsattribute.aspx 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) -- Michael Hutchinson http://mjhutchinson.com _______________________________________________ Gtk-sharp-list maillist - Gtk-sharp-list@lists.ximian.com http://lists.ximian.com/mailman/listinfo/gtk-sharp-list