--
You received this message because you are subscribed to the Google Groups "Kivy users support" group.
To unsubscribe from this group and stop receiving emails from it, send an email to kivy-users+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/43fb882a-230d-466f-870c-fe6eac933468n%40googlegroups.com.
You do NOT use the Vkeyboard directly as described here: https://kivy.org/doc/stable/api-kivy.uix.vkeyboard.html?highlight=vkeyboard#module-kivy.uix.vkeyboard
To Request the keyboard see:
See: https://kivy.org/doc/stable/api-kivy.core.window.html#kivy.core.window.Keyboard
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/CAGpYEyzzCF%2Bo%2B7%2BpEwZ8G11NCDKveK0idVVo4UA2KUwQRKuDCA%40mail.gmail.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/61167983.1c69fb81.d8499.aca1SMTPIN_ADDED_MISSING%40gmr-mx.google.com.
The example below, uses the Config object to bring up the virtual keyboard. Clicking on the left side of the screen outside of the TextInput will cause the VKeyboard to close. Clicking on the text input or the right side of the screen will cause the virtual keyboard to open. Pressing spacebar, up, left or right, will cause the appropriate section on the right side of the screen to highlight.
Note I have set the ids on the KeyLabels to match the keycodes to simplify the code.
from kivy.config import Config
# must be before kivy.app loads, this will use the kivy virtual & system keyboard
Config.set('kivy', 'keyboard_mode', 'systemanddock')
from kivy.app import App
from kivy.lang import Builder
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.label import Label
from kivy.core.window import Window
from kivy.properties import NumericProperty
kv = """
<KeyLabel>:
canvas:
Color:
rgb: .5, .5, .5
Line:
width: 2
rectangle: (*self.pos, *self.size)
canvas:
Color:
rgba: .3, .3, .3, root.down_opacity
Rectangle:
pos: self.pos
size: self.size
BoxLayout:
RelativeLayout:
orientation: 'vertical'
TextInput:
hint_text: 'Enter Name Here'
size_hint: .7, None
height: 30
pos_hint: {'center_x': 0.5, 'center_y': 0.5}
RightSideLayout:
orientation: 'vertical'
Label:
text: 'Click on this side to capture keys'
size_hint_y: None
height: 48
GridLayout:
padding: 10
size_hint_y: None
height: 48 * 2
cols: 3
rows: 2
KeyLabel:
KeyLabel:
id: up
text: 'Up'
KeyLabel:
KeyLabel:
id: left
text: 'Left'
KeyLabel:
id: spacebar
text: 'Spacebar'
KeyLabel:
id: right
text: 'Right'
Label:
"""
class KeyLabel(Label):
down_opacity = NumericProperty()
class RightSideLayout(BoxLayout):
def __init__(self, **kwargs):
super().__init__(**kwargs)
self._keyboard = None
def on_touch_down(self, touch):
if self.collide_point(*touch.pos):
self._keyboard = Window.request_keyboard(self._keyboard_closed, self)
self._keyboard.bind(on_key_down=self._on_keyboard_down)
self._keyboard.bind(on_key_up=self._on_keyboard_up)
print('Keyboard Opened')
return True
return False
def _keyboard_closed(self):
print('Keyboard Closed')
self._keyboard.unbind(on_key_down=self._on_keyboard_down)
self._keyboard.unbind(on_key_up=self._on_keyboard_up)
self._keyboard = None
def _on_keyboard_down(self, keyboard, keycode, text, modifiers):
key = keycode[1]
print(f'{key} pressed')
if key in ['left', 'right', 'up', 'spacebar']:
app = App.get_running_app()
app.root.ids[key].down_opacity = .5
def _on_keyboard_up(self, keyboard, keycode):
key = keycode[1]
print(f'{key} released')
if key in ['left', 'right', 'up', 'spacebar']:
app = App.get_running_app()
app.root.ids[key].down_opacity = 0
class KeysApp(App):
def build(self):
return Builder.load_string(kv)
KeysApp().run()
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/CAGpYEyy%2BE3Bm1hEv%2ByPrZo57uPCKQAOG%2BhmCw4OoJjLgHMT8hg%40mail.gmail.com.