Skip to content

Create unified key mappings for all platforms #168

Description

@GoogleCodeExporter
Currently in examples key presses that are handled in 
KeyboardHandler.OnKeyEvent, are checked against raw integer values to check for 
key code. The code for Linux and Windows is as follows:

    # F5
    if (linux and event["native_key_code"] == 71) \
            or (windows and event["windows_key_code"] == 116):
        print("[wxpython.py] F5 pressed, calling"
                " browser.ReloadIgnoreCache()")
        browser.ReloadIgnoreCache()
        return True
    # Escape
    if (linux and event["native_key_code"] == 9) \
            or (windows and event["windows_key_code"] == 27):
        print("[wxpython.py] Esc pressed, calling browser.StopLoad()")
        browser.StopLoad()
        return True
    # F12
    if (linux and event["native_key_code"] == 96) \
            or (windows and event["windows_key_code"] == 123):
        print("[wxpython.py] F12 pressed, calling"
                " browser.ShowDevTools()")
        browser.ShowDevTools()
        return True

The code for Mac is as follows:

    # Cmd+Opt+I
    if event["modifiers"] == 136 and event["character"] == 94:
        browser.ShowDevTools()
        return True
    # F5
    if event["modifiers"] == 0 and event["character"] == 63240:
        browser.ReloadIgnoreCache()
        return True
    # Esc
    if event["modifiers"] == 0 and event["character"] == 27:
        browser.StopLoad()

Actually in this case "123" key code could be replaced with cefpython.VK_F12 on 
Windows. Virtual key codes are provided only for Windows, see the VirtualKey 
wiki page. We should provide similar key codes using VK_ constants for other 
platforms: Mac, Linux.

On Mac and Linux some key codes are similar (Esc), but others like F5 are 
different.

In the kivy_.py example there is a mapping of Linux keys that could be used to 
translate Windows VK key codes to Linux ones. See the translate_to_cef_keycode 
function: 
https://code.google.com/p/cefpython/source/browse/cefpython/cef3/linux/binaries_
64bit/kivy_.py?r=ad99514963ae#355

In the code pasted above, you can see that on all platforms a different 
event[key] is being checked:
 * On Windows it is event["windows_key_code"]
 * On Linux it is event["native_key_code"]
 * On Mac it is event["character"]

I think we should add event["virtual_key"] to simplify things. This virtual_key 
would be checked against cefpython.VK_ constants.

Maybe we should also export all VK_ to a dict? And make it accessible through 
cefpython.virtual_keys? I think this could be useful, for example:

  {
    "a": 65,
    "b": 66,
    ...
  }

Original issue reported on code.google.com by czarek.t...@gmail.com on 21 Jan 2015 at 9:04

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions