Example #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)
Example #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()
Example #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
Example #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)
 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
Example #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
Example #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
Example #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
Example #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
Example #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()
Example #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
Example #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
Example #13
0
 def key_action(self, *args):
     snack(Keyboard.keycode_to_string(None, args[1]))
Example #14
0
 def on_key_up(self, __window, key, *__largs, **__kwargs):
     code = Keyboard.keycode_to_string(None, key)
     self.keys_pressed.remove(code)
Example #15
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
Example #16
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
Example #17
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)