[wxPython] EVT_LIST_KEY_DOWN/event.GetCode()

event.GetCode() caused by EVT_LIST_KEY_DOWN seems to return 0 for every
key.

In ListControl can't catch EVT_KEY_DOWN for RETURN (all others keys
occur),
  also if all parents above have wxWANTS_CHARS,
  also if there is no EVT_LIST_ITEM_ACTIVATED.

(W98/Python1.5.2/wx2.2.2)

Udo

···

_______________________________________________
wxPython-users mailing list
wxPython-users@lists.sourceforge.net
http://lists.sourceforge.net/lists/listinfo/wxpython-users

event.GetCode() caused by EVT_LIST_KEY_DOWN seems to return 0 for every
key.

In ListControl can't catch EVT_KEY_DOWN for RETURN (all others keys
occur),
  also if all parents above have wxWANTS_CHARS,
  also if there is no EVT_LIST_ITEM_ACTIVATED.

(W98/Python1.5.2/wx2.2.2)

Here is the relevant code from wx/src/msw/listctrl.cpp:

        case LVN_KEYDOWN:
            {
                LV_KEYDOWN *info = (LV_KEYDOWN *)lParam;
                WORD wVKey = info->wVKey;

                // get the current selection
                long lItem = GetNextItem(-1,
                                         wxLIST_NEXT_ALL,
                                         wxLIST_STATE_SELECTED);

                // <Enter> or <Space> activate the selected item if any
                if ( lItem != -1 && (wVKey == VK_RETURN || wVKey ==
VK_SPACE) )
                {
                    // TODO this behaviour probably should be optional
                    eventType = wxEVT_COMMAND_LIST_ITEM_ACTIVATED;
                    event.m_itemIndex = lItem;
                }
                else
                {
                    eventType = wxEVT_COMMAND_LIST_KEY_DOWN;
                    event.m_code = wxCharCodeMSWToWX(wVKey);
                }

                if ( lItem != -1 )
                {
                    // fill the other fields too
                    event.m_item.m_text = GetItemText(lItem);
                    event.m_item.m_data = GetItemData(lItem);
                }
            }
            break;

So if the listctrl gets the LVN_KEYDOWN message and it's a space or return
then an activated event is generated, otherwise a list_key_down event is
generated. The comments for wxCharCodeMSWToWX say this:

// Returns 0 if was a normal ASCII value, not a special key. This indicates
that
// the key should be ignored by WM_KEYDOWN and processed by WM_CHAR instead.

So apparently it is only for non-ASCII keys. Event if it gave you real
values it still wouldn't help your problem as this message is not being
generated otherwise you would be getting an activated event.

I've asked about this activation issue on the wx-devel list...

···

--
Robin Dunn
Software Craftsman
robin@AllDunn.com Java give you jitters?
http://wxPython.org Relax with wxPython!

_______________________________________________
wxPython-users mailing list
wxPython-users@lists.sourceforge.net
http://lists.sourceforge.net/lists/listinfo/wxpython-users