Keyboard Input [was: The "loop and a half"]

Mikhail V mikhailwas at gmail.com
Tue Oct 10 11:53:46 EDT 2017


Chris Angelico wrote:

> On Mon, Oct 9, 2017 at 7:05 PM, Mikhail V <mikhailwas at gmail.com> wrote:
> > The first thing a developer should provide - the keys and mouse input
> > should be
> > *customizable* by the user. It is so by most serious application I have
> > ever used.
>
> And they most certainly are. Often, in something in the host platform.
> For instance, Xfce allows me to change the keys used for various
> purposes, by going into the menu and choosing "Settings" and then
> "Keyboard". (Or, of course, by editing the config files.) The most
> obvious and dramatic change you can do is to choose a specific
> keyboard layout - Qwerty vs Dvorak, US vs German, etc, etc, etc. Do
> you think that sort of thing should be in the hands of the
> application, or the platform? (Note that I'm not saying "OS" here.
> Usually the platform is at a higher level than that; in my case, I
> would consider Xfce (my desktop manager) to be that.)


I am not sure I correctly understand your question.
Do you ask whether the application should bypass the OS
selected layout and use own character input tables?
It is of course possible, but since the OS provides
input events, why not use those?
We were speaking about a text editor, so yes this
will be useful if one wants multilingual text input.

Also I am almost sure I can programmatically switch
the layout pages from Python (some Winapi calls I suppose)
So theoretically, based only on keyb scancodes, one
can use own LUTS and flags to replicate the unicode
input. I personally never wrote apps with multilingual text input though.

Seems that for keyboard input everything is already invented and
well-established.
Below is a minimal app showing pressed keys.
Try switching layouts and see 'unicode'  field changing for
same key scancode.


import pygame
pygame.init()
window_w = 300            # display width
window_h = 200            # display height
pygame.display.set_mode((window_w, window_h))
clock = pygame.time.Clock( )
FPS = 15
MainLoop = True
while MainLoop :
    clock.tick(FPS)
    for E in pygame.event.get():
        if E.type == pygame.QUIT:
            MainLoop = False
        if E.type == pygame.KEYDOWN:
            print (E)
            if E.key == pygame.K_ESCAPE:
                MainLoop = False
pygame.quit( )




Mikhail



More information about the Python-list mailing list