Trapping shift, escape and return keys for a ComboBox

Article ID: 986
Last updated: 05 Feb, 2008
Article ID: 986
Last updated: 05 Feb, 2008
Revision: 1
Views: 2908
Posted: 02 Sep, 1997
by Dean J.
Updated: 05 Feb, 2008
by Dean J.
Problem


This sample illustrates how the user can trap the shift, return and escape keys for a ComboBox control on UNIX.


Cause


There is no specific function to trap these keys for a ComboBox. All events for a ComboBox are directed to the arrow button. We want to direct the events to the edit line portion.


Action


Below is an example of how to trap the return, escape and shift keys for a ComboBox in Motif.
  1. Add an Event Handler in the constructor of your comboBox.
  2. Add a method that is called upon receiving a printable character.
    MyComboBox::MyComboBox(zWindow *w,zSizer *s,DWORD style_, const char
    *c,int i)
      :zComboBoxFull(w,s,style_,c,i){
            add(Item1);
            add(Item2);
            add(Item3);

            // Add event handler, notice the getText() method, this is the text portion of the ComboBox
            XtAddEventHandler(getText(),KeyPressMask,False,(XtEventHandler)MyComboBox::keybInput,
                   
    (XtPointer) this);
            show();
    }

    void MyComboBox::keybInput(Widget w, XtPointer ehTag, XEvent *xev,
    Boolean *contin) {
            KeySym key;
            char buf[20];
            buf[0] =0;
            int len =0;
            if (xev->type  ==
    KeyPress) {
                   
    len = XLookupString((XKeyEvent*) xev,buf,20,&key,&app->xcompose);
                   
    if (len == 0) return;
                   
    // trap keystrokes here
                   
    if(key == XK_Return) printf(Enter
    );
                   
    if(key == XK_Escape) printf(Escape
    );
                   
    if(key == XK_Shift_L) printf(Shift
    );
            }

    }

This article was:   Helpful | Not helpful
Report an issue
Article ID: 986
Last updated: 05 Feb, 2008
Revision: 1
Views: 2908
Posted: 02 Sep, 1997 by Dean J.
Updated: 05 Feb, 2008 by Dean J.

Others in this category