Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[input]Add caps and numlock to the modifiers #6286

Merged
merged 1 commit into from May 13, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
52 changes: 30 additions & 22 deletions kivy/core/window/window_sdl2.py
Expand Up @@ -37,14 +37,20 @@
from kivy.compat import unichr
from collections import deque

KMOD_LCTRL = 64
KMOD_RCTRL = 128
KMOD_RSHIFT = 2
KMOD_LSHIFT = 1
KMOD_RALT = 512
KMOD_LALT = 256
KMOD_LMETA = 1024
KMOD_RMETA = 2048

# SDL_keycode.h, https://wiki.libsdl.org/SDL_Keymod
KMOD_NONE = 0x0000
KMOD_LSHIFT = 0x0001
KMOD_RSHIFT = 0x0002
KMOD_LCTRL = 0x0040
KMOD_RCTRL = 0x0080
KMOD_LALT = 0x0100
KMOD_RALT = 0x0200
KMOD_LGUI = 0x0400
KMOD_RGUI = 0x0800
KMOD_NUM = 0x1000
KMOD_CAPS = 0x2000
KMOD_MODE = 0x4000

SDLK_SHIFTL = 1073742049
SDLK_SHIFTR = 1073742053
Expand Down Expand Up @@ -145,9 +151,10 @@ def __init__(self, **kwargs):
self._win = _WindowSDL2Storage()
super(WindowSDL, self).__init__()
self._mouse_x = self._mouse_y = -1
self._meta_keys = (KMOD_LCTRL, KMOD_RCTRL, KMOD_RSHIFT,
KMOD_LSHIFT, KMOD_RALT, KMOD_LALT, KMOD_LMETA,
KMOD_RMETA)
self._meta_keys = (
KMOD_LCTRL, KMOD_RCTRL, KMOD_RSHIFT,
KMOD_LSHIFT, KMOD_RALT, KMOD_LALT, KMOD_LGUI,
KMOD_RGUI, KMOD_NUM, KMOD_CAPS, KMOD_MODE)
self.command_keys = {
27: 'escape',
9: 'tab',
Expand Down Expand Up @@ -748,37 +755,38 @@ def mainloop(self):
Logger.info("WindowSDL: exiting mainloop and closing.")
self.close()

#
# Pygame wrapper
#
def _update_modifiers(self, mods=None, key=None):
# Available mod, from dir(pygame)
# 'KMOD_ALT', 'KMOD_CAPS', 'KMOD_CTRL', 'KMOD_LALT',
# 'KMOD_LCTRL', 'KMOD_LMETA', 'KMOD_LSHIFT', 'KMOD_META',
# 'KMOD_MODE', 'KMOD_NONE'
if mods is None and key is None:
return
modifiers = set()

if mods is not None:
if mods & (KMOD_RSHIFT | KMOD_LSHIFT):
modifiers.add('shift')
if mods & (KMOD_RALT | KMOD_LALT):
if mods & (KMOD_RALT | KMOD_LALT | KMOD_MODE):
modifiers.add('alt')
if mods & (KMOD_RCTRL | KMOD_LCTRL):
modifiers.add('ctrl')
if mods & (KMOD_RMETA | KMOD_LMETA):
if mods & (KMOD_RGUI | KMOD_LGUI):
modifiers.add('meta')
if mods & KMOD_NUM:
modifiers.add('numlock')
if mods & KMOD_CAPS:
modifiers.add('capslock')

if key is not None:
if key in (KMOD_RSHIFT, KMOD_LSHIFT):
modifiers.add('shift')
if key in (KMOD_RALT, KMOD_LALT):
if key in (KMOD_RALT, KMOD_LALT, KMOD_MODE):
modifiers.add('alt')
if key in (KMOD_RCTRL, KMOD_LCTRL):
modifiers.add('ctrl')
if key in (KMOD_RMETA, KMOD_LMETA):
if key in (KMOD_RGUI, KMOD_LGUI):
modifiers.add('meta')
if key == KMOD_NUM:
modifiers.add('numlock')
if key == KMOD_CAPS:
modifiers.add('capslock')

self._modifiers = list(modifiers)
return
Expand Down