Ejemplo n.º 1
0
 def on_key_down(self, __win, key, *__largs, **__kwargs):
     if self.gameworld.state != 'main':  # don't receive kbd events from menus etc....
         return
     # very dirty hack, but: we don't have any instance of keyboard anywhere, and
     # keycode_to_string should be in fact classmethod, so passing None as self is safe
     code = Keyboard.keycode_to_string(Window._system_keyboard, key)
     self.keys_pressed.add(code)
Ejemplo n.º 2
0
    def on_key_up(self, _win, key, *_args, **_kwargs):
        code = Keyboard.keycode_to_string(Window._system_keyboard, key)

        if code != 'a' and code != 'spacebar':
            return

        self.shout()
Ejemplo n.º 3
0
    def read_key(self, obj, keycode, something):

        #  print((Keyboard.keycode_to_string(obj, keycode)))

        if (Keyboard.keycode_to_string(obj, keycode)) == "right":

            if not change_mod.focus and not change_num.focus:
                if self.type_dice == 100:
                    self.cb_list[DICES.index(self.type_dice)].active = False
                    self.cb_list[0].active = True
                elif self.type_dice == 0:
                    self.cb_list[0].active = True
                else:
                    self.cb_list[DICES.index(self.type_dice)].active = False
                    self.cb_list[DICES.index(self.type_dice) + 1].active = True

        if (Keyboard.keycode_to_string(obj, keycode)) == "left":
            if not change_mod.focus and not change_num.focus:
                if self.type_dice == 2:
                    self.cb_list[DICES.index(self.type_dice)].active = False
                    self.cb_list[len(self.cb_list) - 1].active = True
                elif self.type_dice == 0:
                    self.cb_list[0].active = True
                else:
                    self.cb_list[DICES.index(self.type_dice)].active = False
                    self.cb_list[DICES.index(self.type_dice) - 1].active = True

        if (Keyboard.keycode_to_string(obj, keycode)) == "enter":
            self.lanzar_dados(self.btn)
        if (Keyboard.keycode_to_string(obj, keycode)) == "up":

            if change_num.focus:
                change_num.focus = False
                change_mod.focus = True
            else:
                change_num.focus = True
                change_mod.focus = False
        if (Keyboard.keycode_to_string(obj, keycode)) == "down":
            change_num.focus = False
            change_mod.focus = False
        if (Keyboard.keycode_to_string(obj, keycode)) == "r":
            change_num.text = "1"
            change_mod.text = "0"
        if (Keyboard.keycode_to_string(obj, keycode)) == "n":
            change_num.focus = True
            change_num.text = ""
        if (Keyboard.keycode_to_string(obj, keycode)) == "m":
            change_mod.focus = True
            change_mod.text = ""
        if (Keyboard.keycode_to_string(obj, keycode)) == "spacebar":
            change_num.focus = False
            change_mod.focus = False
Ejemplo n.º 4
0
    def on_key_down(self, window, key, *largs, **kwargs):
        # very dirty hack, but: we don't have any instance of keyboard anywhere, and
        # keycode_to_string should be in fact classmethod, so passing None as self is safe
        code = Keyboard.keycode_to_string(None, key)
        self.keys_pressed.add(code)

        if code == 'spacebar':
            self.shoot(drop=True)
Ejemplo n.º 5
0
 def parse_key_down(self, keyboard, key, codepoint, text, modifier, *args):
     '''Parse keys and generate the formatted keyboard shortcut
     '''
     key_str = Keyboard.keycode_to_string(Window._system_keyboard, key)
     modifier.sort()
     value = str(modifier) + ' + ' + key_str
     if value in self.map:
         self.map.get(value)[0]()
         return True
Ejemplo n.º 6
0
 def parse_key_down(self, keyboard, key, codepoint, text, modifier, *args):
     '''Parse keys and generate the formatted keyboard shortcut
     '''
     key_str = Keyboard.keycode_to_string(Window._system_keyboard, key)
     modifier.sort()
     value = str(modifier) + ' + ' + key_str
     if value in self.map:
         self.map.get(value)[0]()
         return True
Ejemplo n.º 7
0
    def _on_key_down(self, keyboard, key, codepoint, text, modifier, **kwargs):
        '''Listen keyboard to create shortcuts. Update class properties
        '''
        self.key = Keyboard.keycode_to_string(Window._system_keyboard, key)
        if self.key in ['ctrl', 'shift', 'alt']:
            self.key = ''
        if modifier is None:
            modifier = []
        self.has_ctrl = 'ctrl' in modifier
        self.has_shift = 'shift' in modifier
        self.has_alt = 'alt' in modifier

        return True
Ejemplo n.º 8
0
    def _on_key_down(self, keyboard, key, codepoint, text, modifier, **kwargs):
        """Listen keyboard to create shortcuts. Update class properties
        """
        self.key = Keyboard.keycode_to_string(Window._system_keyboard, key)
        if self.key in ["ctrl", "shift", "alt"]:
            self.key = ""
        if modifier is None:
            modifier = []
        self.has_ctrl = "ctrl" in modifier
        self.has_shift = "shift" in modifier
        self.has_alt = "alt" in modifier

        return True
Ejemplo n.º 9
0
    def _on_key_down(self, keyboard, key, codepoint, text, modifier, **kwargs):
        '''Listen keyboard to create shortcuts. Update class properties
        '''
        self.key = Keyboard.keycode_to_string(Window._system_keyboard, key)
        if self.key in ['ctrl', 'shift', 'alt']:
            self.key = ''
        if modifier is None:
            modifier = []
        self.has_ctrl = 'ctrl' in modifier
        self.has_shift = 'shift' in modifier
        self.has_alt = 'alt' in modifier

        return True
Ejemplo n.º 10
0
    def handle_key(self, keyboard, key, codepoint, text, modifier, *args):

        key_str = Keyboard.keycode_to_string(Window._system_keyboard, key)
        modifier.sort()
        if modifier:
            value = '_'.join(modifier) + '_' + key_str
        else:
            value = key_str

        callable_method = 'do_' + value

        try:
            func = getattr(self, callable_method)
        except AttributeError:
            pass
        else:
            func()
Ejemplo n.º 11
0
 def _on_keyboard_down(self, keyboard, key, codepoint,
                       text, modifier, *args):
     '''To detect which key is pressed
     '''
     if modifier:
         return False
     key_str = Keyboard.keycode_to_string(Window._system_keyboard, key)
     if key_str == 'up':
         v = self.adapter.get_view(self.prev_selection - 1)
         if v is not None:
             self.adapter.handle_selection(v)
             return True
     if key_str == 'down':
         v = self.adapter.get_view(self.prev_selection + 1)
         if v is not None:
             self.adapter.handle_selection(v)
             return True
     if key_str == 'enter':
         self.dispatch('on_select')
         return True
Ejemplo n.º 12
0
 def _on_keyboard_down(self, keyboard, key, codepoint, text, modifier,
                       *args):
     '''To detect which key is pressed
     '''
     if modifier:
         return False
     key_str = Keyboard.keycode_to_string(Window._system_keyboard, key)
     if key_str == 'up':
         v = self.adapter.get_view(self.prev_selection - 1)
         if v is not None:
             self.adapter.handle_selection(v)
             return True
     if key_str == 'down':
         v = self.adapter.get_view(self.prev_selection + 1)
         if v is not None:
             self.adapter.handle_selection(v)
             return True
     if key_str == 'enter':
         self.dispatch('on_select')
         return True
Ejemplo n.º 13
0
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
from random import randint
from kivy.config import Config
Config.set("graphics", "fullscreen", "auto")
from kivy.graphics import Color, Rectangle
from kivy.app import App
from kivy.uix.widget import Widget
from kivy.clock import Clock
from kivy.core.window import Window, Keyboard
from kivy.graphics.context_instructions import Scale
from kivy.uix.label import Label


vanster = Keyboard.string_to_keycode(None, "left")
hoger = Keyboard.string_to_keycode(None, "right")
ner = Keyboard.string_to_keycode(None, "down")
upp = Keyboard.string_to_keycode(None, "up")

gron = (0,1,0)
vit = (1,1,1)
banan = (0,0,1)


def flytta_pos(sak, sidled, hojdled):
    ny_x = sak.x + sidled
    ny_y = sak.y + hojdled
    sak.pos = ny_x, ny_y


class Sak(Widget):
Ejemplo n.º 14
0
 def key_action(self, *args):
     snack(Keyboard.keycode_to_string(None, args[1]))
Ejemplo n.º 15
0
 def on_key_up(self, __window, key, *__largs, **__kwargs):
     code = Keyboard.keycode_to_string(None, key)
     self.keys_pressed.remove(code)
Ejemplo n.º 16
0
 def on_key_up(self, _win, key, *_args, **_kwargs):
     code = Keyboard.keycode_to_string(Window._system_keyboard, key)
     if code in self.keys_pressed:
         self.keys_pressed.remove(code)
Ejemplo n.º 17
0
 def on_key_down(self, win, key, scancode, codepoint, modifier):
     code = Keyboard.keycode_to_string(Window._system_keyboard, key)
     if key == 13 and modifier == ['alt'] or code == 'f11':
         Clock.schedule_once(partial(self.toggle_fs, win), 0.1)
         return True
Ejemplo n.º 18
0
 def on_key_up(self, _win, key, *_args, **_kwargs):
     code = Keyboard.keycode_to_string(Window._system_keyboard, key)
     # Logger.debug("code=%s", code)
     if self.gameworld.state == 'levelnum' and code == 'spacebar':
         self.on_play()
         return True
Ejemplo n.º 19
0
    def events_program(self, instance, keyboard, keycode, text, modifiers):
        c = Keyboard()
        """Called when you press a Key"""
        app = App.get_running_app()
        current_screen = app.manager.current_screen
        hk_next_page = app.config.get("Hotkeys", "hk_next_page")
        hk_prev_page = app.config.get("Hotkeys", "hk_prev_page")
        hk_open_page_nav = app.config.get("Hotkeys", "hk_open_page_nav")
        hk_open_collection = app.config.get("Hotkeys", "hk_open_collection")
        hk_return_comic_list = app.config.get(
            "Hotkeys", "hk_return_comic_list"
        )
        hk_return_base_screen = app.config.get(
            "Hotkeys", "hk_return_base_screen"
        )
        hk_toggle_navbar = app.config.get("Hotkeys", "hk_toggle_navbar")

        hk_toggle_fullscreen = app.config.get(
            "Hotkeys", "hk_toggle_fullscreen"
        )
        Logger.debug(f"keyboard:{keyboard}")
        if current_screen.name not in self.LIST_SCREENS:
            if keyboard in (c.string_to_keycode(hk_next_page), 275):
                current_screen.load_next_slide()
            elif keyboard in (c.string_to_keycode(hk_prev_page), 276):
                current_screen.load_prev_slide()
            elif keyboard == c.string_to_keycode(hk_open_page_nav):
                current_screen.page_nav_popup_open()
            elif keyboard == c.string_to_keycode(hk_open_collection):
                current_screen.comicscreen_open_collection_popup()
            elif keyboard == c.string_to_keycode(hk_toggle_navbar):
                current_screen.toggle_option_bar()
            elif keyboard == c.string_to_keycode(hk_return_comic_list):
                app.switch_readinglists_screen()
            elif keyboard == c.string_to_keycode(hk_return_base_screen):
                app.show_action_bar()
                app.manager.current = "base"
            elif keyboard in (1001, 27):
                if self.nav_drawer.state == "open":
                    self.nav_drawer.toggle_nav_drawer()
                self.back_screen(event=keyboard)
            elif keyboard == c.string_to_keycode(hk_toggle_fullscreen):
                self.toggle_full_screen()
        else:
            if keyboard in (282, 319):
                pass
            elif keyboard == c.string_to_keycode(hk_toggle_fullscreen):
                self.toggle_full_screen()
            elif keyboard == c.string_to_keycode(hk_return_comic_list):
                app.manager.current = "server_readinglists_screen"
            elif keyboard == c.string_to_keycode(hk_return_base_screen):
                app.show_action_bar()
                app.switch_base_screen()
            elif keyboard in (1001, 27):
                if self.nav_drawer.state == "open":
                    self.nav_drawer.toggle_nav_drawer()
                self.back_screen(event=keyboard)
        return True