Custom keyboard on Android

651 views
Skip to first unread message

Phisatho

unread,
Aug 16, 2013, 5:37:34 AM8/16/13
to kivy-...@googlegroups.com
I want to use a custom keyboard (Numeric only) layout on Android.
But I don't know where to place the json file. I searched my device, but could not find any keyboards folder or json files.
Will placing the json in the app folder and use vk.layout_path = os.getcwd() help?

The code I am trying to use is

Config.set('kivy', 'keyboard_layout', 'numeric')

A sample code will be very helpful

Regards,

Shibu

ZenCODE

unread,
Aug 16, 2013, 1:58:31 PM8/16/13
to kivy-...@googlegroups.com
Hi Shibu

I also never figured this out. https://github.com/kivy/kivy/issues/958

If you find out how to do this, please share it back here. I would like to update the docs with a clear example of how to do this. So we can pay it back ;-)

Thanks. Peace out

Phisatho

unread,
Aug 16, 2013, 2:24:24 PM8/16/13
to kivy-...@googlegroups.com
I found the keyboards folder at /data/user/11/org.kivy.pygame/files/lib/python2.7/site-packages/kivy/data/keyboards (quite a long path!).

However, copying numeric.json to this folder did not help. Further, I suppose copying the json manually is not practical when I distribute my app to friends as I guess I was able access this folder because my device is rooted.

ZenCODE

unread,
Jan 10, 2014, 9:03:28 AM1/10/14
to kivy-...@googlegroups.com
Hi

@Phisatho. Okay, I finally got mine working and updated the docs accordingly.

http://kivy.org/docs/api-kivy.core.window.html?highlight=request_keyboard#kivy.core.window.WindowBase.request_keyboard

From 1.8.0, you can now load the "json" directly from your app folder via:
    vkeyboard.layout = "my_keyboard.json"

Note from the docs, you need to set your "keyboard_mode" to "dock" before it's run.

Peace

Leonardo Rodriguez

unread,
Jan 16, 2018, 9:18:54 AM1/16/18
to Kivy users support
Hi, I didn't make it work. Could you please tell me what is wrong? here is my class, I used the doc example and before the app starts.

Config.set('kivy', 'keyboard_mode', 'dock')


class IntegerInput(TextInput):
def __init__(self, **kwargs):
super(IntegerInput, self).__init__(**kwargs)
keyboard = Window.request_keyboard(
self._keyboard_close, self)
if keyboard.widget:
vkeyboard = self._keyboard.widget
vkeyboard.layout = 'numeric.json'

def _keyboard_close(self):
pass
def insert_text(self, substring, from_undo=False):
if substring.isnumeric():
if hasattr(self, "maxdigits"):
if len(self.text) < self.maxdigits:
return super(IntegerInput, self).insert_text(substring, from_undo=from_undo)
else:
return super(IntegerInput, self).insert_text(substring, from_undo=from_undo)

ZenCODE

unread,
Jan 17, 2018, 2:40:48 PM1/17/18
to Kivy users support
There is a lot I need to do to get this working, but this works IF you have numeric.json file in the app folder. Next time, please post code we can run :-)

from kivy.config import Config
from kivy.app import App
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.textinput import TextInput
from kivy.core.window import Window


Config.set('kivy', 'keyboard_mode', 'dock')


class IntegerInput(TextInput):

def __init__(self, **kwargs):
super(IntegerInput, self).__init__(**kwargs)
keyboard = Window.request_keyboard(
self._keyboard_close, self)
if keyboard.widget:
            vkeyboard = keyboard.widget

vkeyboard.layout = 'numeric.json'

def _keyboard_close(self):
pass

def insert_text(self, substring, from_undo=False):
if substring.isnumeric():
if hasattr(self, "maxdigits"):
if len(self.text) < self.maxdigits:
return super(IntegerInput, self).insert_text(substring, from_undo=from_undo)
else:
return super(IntegerInput, self).insert_text(substring, from_undo=from_undo)


class TestApp(App):
def build(self):
box = BoxLayout()
box.add_widget(IntegerInput())
box.add_widget(BoxLayout())
return box


TestApp().run()

Davide Chiarello

unread,
Mar 18, 2018, 7:39:11 PM3/18/18
to Kivy users support
tried to use your code here: https://github.com/dav01it/kivy_st_widgets
Created a FloatTextInput: works filtering input on desktop but no luck on android for a numeric keyboard!

but I get a numeric keyboard suddenly overlapped by system keyboard.

Tom Grundy

unread,
Dec 23, 2018, 9:44:27 AM12/23/18
to Kivy users support
I get the same symptom: a numeric keyboard suddenly overlapped by system keyboard.  Did you ever find a way to prevent the system keyboard and only show the virtual keyboard?  I have the same question here.
Reply all
Reply to author
Forward
0 new messages