WXK_ for numbers on top row of keyboard?

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

WXK_ for numbers on top row of keyboard?

Alex Hall-3
Hi all,
I am trying to attach functions to the numbers on the top of the
keyboard with an accelerator table, but I cannot find the names of the
number keys. I found the F keys, the Numpad keys, and the Special keys
(whatever they are) but nothing about the regular keys above the
letters on the standard American keyboard. I tried WXK_One and WXK_1,
but neither worked. I also tried WXK_SPECIAL1, but that also failed.
Thanks in advance for any info. I know it is just something simple,
but I cannot find it, even in the list of key names at wxpython.org.

--
Have a great day,
Alex (msg sent from GMail website)
[hidden email]; http://www.facebook.com/mehgcap

--
To unsubscribe, send email to [hidden email]
or visit http://groups.google.com/group/wxPython-users?hl=en
Reply | Threaded
Open this post in threaded view
|

Re: WXK_ for numbers on top row of keyboard?

Cody Precord
Hi,


On Thu, Aug 5, 2010 at 9:51 AM, Alex Hall <[hidden email]> wrote:
> Hi all,
> I am trying to attach functions to the numbers on the top of the
> keyboard with an accelerator table, but I cannot find the names of the
> number keys. I found the F keys, the Numpad keys, and the Special keys
> (whatever they are) but nothing about the regular keys above the
> letters on the standard American keyboard. I tried WXK_One and WXK_1,
> but neither worked. I also tried WXK_SPECIAL1, but that also failed.
> Thanks in advance for any info. I know it is just something simple,
> but I cannot find it, even in the list of key names at wxpython.org.

They are probably like the regular keyboard letter keys where you need
to check the char code.

1 key == ord('1')
2 key == ord('2')
etc...

Can't say I remember trying this before but this is how I would expect
it to work.



Cody

--
To unsubscribe, send email to [hidden email]
or visit http://groups.google.com/group/wxPython-users?hl=en
Reply | Threaded
Open this post in threaded view
|

Re: WXK_ for numbers on top row of keyboard?

Mike Driscoll
In reply to this post by Alex Hall-3
Hi Alex,

On Aug 5, 9:51 am, Alex Hall <[hidden email]> wrote:

> Hi all,
> I am trying to attach functions to the numbers on the top of the
> keyboard with an accelerator table, but I cannot find the names of the
> number keys. I found the F keys, the Numpad keys, and the Special keys
> (whatever they are) but nothing about the regular keys above the
> letters on the standard American keyboard. I tried WXK_One and WXK_1,
> but neither worked. I also tried WXK_SPECIAL1, but that also failed.
> Thanks in advance for any info. I know it is just something simple,
> but I cannot find it, even in the list of key names at wxpython.org.
>
> --
> Have a great day,
> Alex (msg sent from GMail website)

There are no special WXK codes. The key to finding the answer was the
wxPython Demo. They have a handy KeyEvents demo in there in the
"Process and Events" section. Anyway, in your key event handler, do
something like this:

<code>

keycode = evt.GetKeyCode()
keyname = keyMap.get(keycode, None)
if keyname is None:
    if keycode < 256:
        if keycode == 0:
            keyname = "NUL"
        elif keycode < 27:
            keyname = "Ctrl-%s" % chr(ord('A') + keycode-1)
        else:
            keyname = "\"%s\"" % chr(keycode)
    else:
        keyname = "(%s)" % keycode

</code>

Then you can use the "keyname" variable to check what button was
pressed. Hopefully that makes sense and I didn't botch the code...

-------------------
Mike Driscoll

Blog:   http://blog.pythonlibrary.org

--
To unsubscribe, send email to [hidden email]
or visit http://groups.google.com/group/wxPython-users?hl=en
Reply | Threaded
Open this post in threaded view
|

Re: Re: WXK_ for numbers on top row of keyboard?

Robin Dunn
On 8/5/10 8:08 AM, Mike Driscoll wrote:

> Hi Alex,
>
> On Aug 5, 9:51 am, Alex Hall<[hidden email]>  wrote:
>> Hi all,
>> I am trying to attach functions to the numbers on the top of the
>> keyboard with an accelerator table, but I cannot find the names of the
>> number keys. I found the F keys, the Numpad keys, and the Special keys
>> (whatever they are) but nothing about the regular keys above the
>> letters on the standard American keyboard. I tried WXK_One and WXK_1,
>> but neither worked. I also tried WXK_SPECIAL1, but that also failed.
>> Thanks in advance for any info. I know it is just something simple,
>> but I cannot find it, even in the list of key names at wxpython.org.
>>
>> --
>> Have a great day,
>> Alex (msg sent from GMail website)
>
> There are no special WXK codes. The key to finding the answer was the
> wxPython Demo. They have a handy KeyEvents demo in there in the
> "Process and Events" section. Anyway, in your key event handler, do
> something like this:
>
> <code>
>
> keycode = evt.GetKeyCode()
> keyname = keyMap.get(keycode, None)
> if keyname is None:
>      if keycode<  256:
>          if keycode == 0:
>              keyname = "NUL"
>          elif keycode<  27:
>              keyname = "Ctrl-%s" % chr(ord('A') + keycode-1)
>          else:
>              keyname = "\"%s\"" % chr(keycode)
>      else:
>          keyname = "(%s)" % keycode
>
> </code>


That ugly code is only needed for the demo because of all the other
stuff it is doing there.  As Cody mentioned the key code for normal
alphanumeric keys on the keyboard is simply the ASCII value of the
character.


--
Robin Dunn
Software Craftsman
http://wxPython.org

--
To unsubscribe, send email to [hidden email]
or visit http://groups.google.com/group/wxPython-users?hl=en
Reply | Threaded
Open this post in threaded view
|

Re: WXK_ for numbers on top row of keyboard?

Mike Driscoll


On Aug 5, 11:03 am, Robin Dunn <[hidden email]> wrote:

> On 8/5/10 8:08 AM, Mike Driscoll wrote:
>
>
>
> > Hi Alex,
>
> > On Aug 5, 9:51 am, Alex Hall<[hidden email]>  wrote:
> >> Hi all,
> >> I am trying to attach functions to the numbers on the top of the
> >> keyboard with an accelerator table, but I cannot find the names of the
> >> number keys. I found the F keys, the Numpad keys, and the Special keys
> >> (whatever they are) but nothing about the regular keys above the
> >> letters on the standard American keyboard. I tried WXK_One and WXK_1,
> >> but neither worked. I also tried WXK_SPECIAL1, but that also failed.
> >> Thanks in advance for any info. I know it is just something simple,
> >> but I cannot find it, even in the list of key names at wxpython.org.
>
> >> --
> >> Have a great day,
> >> Alex (msg sent from GMail website)
>
> > There are no special WXK codes. The key to finding the answer was the
> > wxPython Demo. They have a handy KeyEvents demo in there in the
> > "Process and Events" section. Anyway, in your key event handler, do
> > something like this:
>
> > <code>
>
> > keycode = evt.GetKeyCode()
> > keyname = keyMap.get(keycode, None)
> > if keyname is None:
> >      if keycode<  256:
> >          if keycode == 0:
> >              keyname = "NUL"
> >          elif keycode<  27:
> >              keyname = "Ctrl-%s" % chr(ord('A') + keycode-1)
> >          else:
> >              keyname = "\"%s\"" % chr(keycode)
> >      else:
> >          keyname = "(%s)" % keycode
>
> > </code>
>
> That ugly code is only needed for the demo because of all the other
> stuff it is doing there.  As Cody mentioned the key code for normal
> alphanumeric keys on the keyboard is simply the ASCII value of the
> character.
>
> --
> Robin Dunn
> Software Craftsmanhttp://wxPython.org

OK. Cody's answer must have come in while I was digging in the demo
since it wasn't there when I started my dumb reply. Listen to these
guys, Alex! Ignore my erroneous advice!!!

-------------------
Mike Driscoll

Blog:   http://blog.pythonlibrary.org

--
To unsubscribe, send email to [hidden email]
or visit http://groups.google.com/group/wxPython-users?hl=en
Reply | Threaded
Open this post in threaded view
|

Re: Re: WXK_ for numbers on top row of keyboard?

Robin Dunn
In reply to this post by Robin Dunn
On 8/5/10 9:03 AM, Robin Dunn wrote:

> That ugly code is only needed for the demo because of all the other
> stuff it is doing there. As Cody mentioned the key code for normal
> alphanumeric keys on the keyboard is simply the ASCII value of the
> character.

It's been a while since I've mentioned it, so I should also say that the
key code sent to the KEY_DOWN/KEY_UP events is a "raw" value for the key
that has not had any modifiers, international keyboard maps, or input
method editor functionality applied to it.  If the key down events are
*not* Skip()ed then after one or more key down events a EVT_CHAR event
will be generated where the GetKeyCode and/or GetUnicodeKey is the
"cooked" value, IOW the character that has had the modifiers/etc.
applied to it.

Mike mentioned the KeyEvents sample in the demo.  I recommend that
everybody who doesn't fully understand what I wrote above should play
with that sample until you do.  :-)

--
Robin Dunn
Software Craftsman
http://wxPython.org

--
To unsubscribe, send email to [hidden email]
or visit http://groups.google.com/group/wxPython-users?hl=en