• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
3
Question by Jeremy2300 · Jan 28, 2016 at 03:36 PM · guiinputcontrollerkeyboardbest practices

On Screen Keyboard (PC and Console) best practices

I'm looking at implementing text input for my game. Currently it's a PC, Mac and Linux (Steam) game, but we want to fully support controller input as well (Big Picture Mode, as well as porting to consoles in the future).

There are a number of occurrences where we'll want users to input text for names (utilizing Steam Workshop with in game designs primarily).

I'm wondering if there's a best practice for on screen keyboards for this, or if it's something most people program out themselves with their UI? It's a frustrating thing to search for (using Keyboard as a key word doesn't really bring anything useful up, and the things you do find are primarily for mobile).

It seems like most systems have a built in Keyboard, so I'd hope to just use those. But I'm fairly uncertain the best way to utilize them (and as stated earlier, it's quite difficult to search for).

Thanks in advance for any help/tips, it's greatly appreciated.

Comment
Add comment · Show 2
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image FortisVenaliter · Jan 28, 2016 at 04:07 PM 0
Share

I don't think the built-in keyboard is available for desktop platforms in Unity... In that case, you'd have to write your own, which definitely isn't a trivial task if you're supporting more than one language.

avatar image Jeremy2300 FortisVenaliter · Jan 28, 2016 at 04:18 PM 0
Share

Yeah, that's been on my $$anonymous$$d since talks with our publisher about localization for 'Simplified Chinese, German, French, Russian, Spanish, and Japanese' as suggested languages (they're handling the translations).

I was hoping there were some functions or something else I was missing.

3 Replies

· Add your reply
  • Sort: 
avatar image
12

Answer by Vagonn · Jan 28, 2016 at 04:25 PM

First you need to create VirtualKeyboard.cs script

 using UnityEngine;
 using System;
 using System.Collections;
 using System.Diagnostics;
 using System.Runtime.InteropServices;
 
 public class VirtualKeyboard
 {
     [DllImport("user32")]
     static extern IntPtr FindWindow(String sClassName, String sAppName);
 
     [DllImport("user32")]
     static extern bool PostMessage(IntPtr hWnd, uint Msg, int wParam, int lParam);
 
     private static Process _onScreenKeyboardProcess = null;
 
     /// <summary>
     /// Show the touch keyboard (tabtip.exe).
     /// </summary>
     public void ShowTouchKeyboard()
     {
         ExternalCall("C:\\Program Files\\Common Files\\Microsoft Shared\\ink\\tabtip.exe", null, false);
         //ExternalCall("TABTIP", null, false);
     }
 
     /// <summary>
     /// Hide the touch keyboard (tabtip.exe).
     /// </summary>
     public void HideTouchKeyboard()
     {
         uint WM_SYSCOMMAND = 274;
         int SC_CLOSE = 61536;
         IntPtr ptr = FindWindow("IPTip_Main_Window", null);
         PostMessage(ptr, WM_SYSCOMMAND, SC_CLOSE, 0);
     }
 
     /// <summary>
     /// Show the on screen keyboard (osk.exe).
     /// </summary>
     public void ShowOnScreenKeyboard()
     {
         //ExternalCall("C:\\Windows\\system32\\osk.exe", null, false);
 
         if (_onScreenKeyboardProcess == null || _onScreenKeyboardProcess.HasExited)
             _onScreenKeyboardProcess = ExternalCall("OSK", null, false);
     }
 
     /// <summary>
     /// Hide the on screen keyboard (osk.exe).
     /// </summary>
     public void HideOnScreenKeyboard()
     {
         if (_onScreenKeyboardProcess != null && !_onScreenKeyboardProcess.HasExited)
             _onScreenKeyboardProcess.Kill();
     }
 
     /// <summary>
     /// Set size and location of the OSK.exe keyboard, via registry changes.  Messy, but only known method.
     /// </summary>
     /// <param name='rect'>
     /// Rect.
     /// </param>
     public void RepositionOnScreenKeyboard(Rect rect)
     {
         ExternalCall("REG", @"ADD HKCU\Software\Microsoft\Osk /v WindowLeft /t REG_DWORD /d " + (int)rect.x + " /f", true);
         ExternalCall("REG", @"ADD HKCU\Software\Microsoft\Osk /v WindowTop /t REG_DWORD /d " + (int)rect.y + " /f", true);
         ExternalCall("REG", @"ADD HKCU\Software\Microsoft\Osk /v WindowWidth /t REG_DWORD /d " + (int)rect.width + " /f", true);
         ExternalCall("REG", @"ADD HKCU\Software\Microsoft\Osk /v WindowHeight /t REG_DWORD /d " + (int)rect.height + " /f", true);
     }
 
     private static Process ExternalCall(string filename, string arguments, bool hideWindow)
     {
         ProcessStartInfo startInfo = new ProcessStartInfo();
         startInfo.FileName = filename;
         startInfo.Arguments = arguments;
 
         // if just command, we don't want to see the console displayed
         if (hideWindow)
         {
             startInfo.RedirectStandardOutput = true;
             startInfo.RedirectStandardError = true;
             startInfo.UseShellExecute = false;
             startInfo.CreateNoWindow = true;
         }
 
         Process process = new Process();
         process.StartInfo = startInfo;
         process.Start();
 
         return process;
     }
 }


then call from your script like below

 VirtualKeyboard vk = new VirtualKeyboard();
 
 public void OpenKeyboard()
 {
         {       
             vk.ShowTouchKeyboard();
         }
 }
 
 public void CloseKeyboard()
 {
         {       
             vk.HideTouchKeyboard();
         }
 }

Comment
Add comment · Show 16 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image rizawerx · Mar 06, 2016 at 07:48 AM 0
Share

Thanks a lot @Vagonn !

avatar image Vagonn rizawerx · Mar 06, 2016 at 01:58 PM 0
Share

You are welcome

avatar image rbisso · Jul 09, 2016 at 02:41 AM 0
Share

I love you, @Vagonn ! If I were able to, I'd gladly bear your children. Seriously, thank you!!!

avatar image Vagonn rbisso · Jul 09, 2016 at 02:47 PM 0
Share

You are welcome

avatar image qwetdgxfbgxbvxcn · Jul 09, 2016 at 02:59 AM 0
Share

@Vagonn Thanks a lot!

avatar image Vagonn qwetdgxfbgxbvxcn · Jul 09, 2016 at 02:47 PM 0
Share

You are welcome.

avatar image playg18 · Jul 20, 2016 at 04:33 AM 0
Share

Hello @Vagonn , first of all . Thank you for this. An answered prayer for me. Would like to ask if is there any way to reposition the keyboard?

Thanks

avatar image Vagonn playg18 · Jul 20, 2016 at 05:36 AM 0
Share

Hello. I never tried repositioning keyboard yet

avatar image playg18 Vagonn · Jul 20, 2016 at 06:12 AM 0
Share

oh,.. thanks man :D

avatar image PhilUpO playg18 · Jul 11, 2017 at 11:57 PM 0
Share

Has there been an updated version of the code where the keyboard can be re positioned? Just tried the function now and it doesn't seem to be doing anything.

avatar image iLyxa3D · Nov 04, 2017 at 11:25 PM 0
Share

How to Input.Get$$anonymous$$eyDown from this keyboard?

Show more comments
avatar image
-1

Answer by alex17pat · Sep 05, 2017 at 11:02 AM

One of the Best On Screen Virtual Keyboards which I know are

  1. Free Virtual Keyboard

  2. On-Screen Keyboard Portable

  3. Comfort On-Screen Keyboard Lite

  4. Microsoft On-Screen Keyboard

  5. Click-N-Type

source:- http://merabheja.com/free-on-screen-virtual-keyboards/

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

Answer by kulger · Oct 21, 2016 at 12:16 PM

hello, i tried it's working only under windows 8.

am stucked with window 10 , keyboared never show , even when you click on Tabtip.exe

but when you call it from execute panel "osk" it 's working , am confused .. and i need some help with windows 10,

Comment
Add comment · Show 5 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Vagonn · Oct 21, 2016 at 05:46 PM 0
Share

But, I tested this only with Windows 10 and it's worked

avatar image JerryStreith Vagonn · Mar 30, 2017 at 04:37 PM 0
Share

yes, on windows 10 keyboard never show, only worked for win8

avatar image sergeMensah Vagonn · Apr 22, 2017 at 02:40 PM 0
Share

hello @vagonn , please can you show me the steps , i had tried but i didn't get any result ,i am confuse please i need some help

avatar image Drakonno Vagonn · Jul 04, 2017 at 03:19 PM 0
Share

I know it is a late response, but @Vagonn shared here a really nice script.

The reason, that someone could have problems with showing the keyboard is that:

vk.ShowTouch$$anonymous$$eyboard();

Touch $$anonymous$$eyboard will work, and show, only on devices with touch input enabled. If You want to show it on standard windows, then You have to call:

Show/Hide OnScreen$$anonymous$$eyboard

methods from the script, for example:

vk.ShowOnScreen$$anonymous$$eyboard();,

and if is not positioned not, set it's rect using:

RepositionOnScreen$$anonymous$$eyboard(Rect rect) ,

with example:

vk.RepositionOnScreen$$anonymous$$eyboard(new Rect(0, 0, 500, 200)

avatar image sergeMensah Drakonno · Jul 12, 2017 at 11:41 PM 0
Share

hi @Drakonno i followed your steps but still nothing is showing i really don't know why it did not work maybe the version of the unity 5.6 i am using please can you show me your step thanks in advance for your help

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

69 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Text Prompt Problem 1 Answer

Activate GUI Button with Enter Key 1 Answer

GUI buttons with alternate activation condition 1 Answer

Removing Joystick Controls 2 Answers

When opening unity plugin via Chrome, all keyboard input is disabled? (sometimes temporarily, sometimes not) 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges