3

I'm using keyboard events following this example:

from kivy.core.window import Window
class PongGame(Widget):
    ball = ObjectProperty(None)
    player1 = ObjectProperty(None)
    player2 = ObjectProperty(None)

    def __init__(self, **kwargs):
        super(PongGame, self).__init__(**kwargs)
        self._keyboard = Window.request_keyboard(self._keyboard_closed, self)
        self._keyboard.bind(on_key_down=self._on_keyboard_down)

    def _keyboard_closed(self):
        self._keyboard.unbind(on_key_down=self._on_keyboard_down)
        self._keyboard = None

    def _on_keyboard_down(self, keyboard, keycode, text, modifiers):
        if keycode[1] == 'w':
            self.player1.center_y += 10
        elif keycode[1] == 's':
            self.player1.center_y -= 10
        elif keycode[1] == 'up':
            self.player2.center_y += 10
        elif keycode[1] == 'down':
            self.player2.center_y -= 10
        return True

Source: How do you check for keyboard events with kivy?

But sometimes when I press esc, the app is left even I didn't order the app to do it. Is there a built-in method of Kivy that makes the app shut down when pressing esc? Is there a way to disable it?

LOG that appears in shell:

[INFO ] [Base ] Leaving application in progress...

EDIT: The keyboard event listener is disabling when I change screen using Screen Manager (kivy.uix.screenmanager)

Community
  • 1
  • 1
João Paulo
  • 6,300
  • 4
  • 51
  • 80

3 Answers3

9

This is an automatic behaviour of kivy. You can turn it off by setting the exit_on_escape config token to 0, as described at http://kivy.org/docs/api-kivy.config.html .

inclement
  • 29,124
  • 4
  • 48
  • 60
  • nice! You answered the question, I'll check it. But what about the event listener? Do I have to reactivate it every time I change screens? – João Paulo Dec 21 '14 at 14:33
  • I'm not sure what you mean about the event listener. I access the keyboard by binding to `Window.on_key_down` etc., which should be unaffected by this kind of thing. – inclement Dec 21 '14 at 14:35
  • Yes, this binding! If I don't call `self._keyboard = Window.request_keyboard(self._keyboard_closed, self)` `self._keyboard.bind(on_key_down=self._on_keyboard_down)` every time I change screen, the app doesn't identify the key pressing anymore. – João Paulo Dec 21 '14 at 14:37
8

Based on @inclement answer,

from kivy.config import Config
Config.set('kivy', 'exit_on_escape', '0')
Community
  • 1
  • 1
Merbin J Anselm
  • 1,014
  • 1
  • 13
  • 15
0

I got this message after asking selenium to wait for an ID and then trying to click it. What fixed it for me was adding a little delay:

time.sleep(3)
kztd
  • 3,121
  • 1
  • 20
  • 18