• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!
  • Hello [name]! Thanks for joining the GMC. Before making any posts in the Tech Support forum, can we suggest you read the forum rules? These are simple guidelines that we ask you to follow so that you can get the best help possible for your issue.

Android Virtual Keyboard

Has anyone had sucess with the new Virtual keyboard? I've tried pulling it out on android but it doesn't work.
I called keyboard_virtual_show(kbv_type_default,kbv_returnkey_default,kbv_autocapitalize_none,0)
and it shows up just fine but game maker doesn't respond to the text input.
Here's what I'm using in the step -

Code:
/// @description Step event Typing
var k=keyboard_lastkey;
var c=keyboard_lastchar;

    if keyboard_check_pressed(vk_anykey)
    {
        //if sbore>=compare
        //global.Name += chr(keyboard_key);
    
         if (k==vk_backspace)
        {
            // delete last character
            global.Name = string_copy(global.Name, 1, string_length(global.Name)-1 );
        }
        else if (k==vk_enter) and string_length(global.Name)>=3//and (global.Name!="")
        {
            // enter was pressed and input wasn't empty : do what have to be done here !
            instance_create_depth(x,y,1,oHighscore)
            if global.mobile keyboard_virtual_hide()
            instance_destroy()
            
        }
        else if k>=65 and k<=90 or k>=97 and k<=122 or k>=48 and k<=57 or k==192 or k==32
        if  string_length(global.Name)<=stringmax
        {
            // 65-90  : upcase letters
            // 122-192 : lowercase letters
            // 48-57  : numbers
            // 192   : I don't remember :P
            // 32   : space
            // Add c to name
            global.Name = global.Name + c;
        } else blink=" "

    }
 
No luck on my side either, I have tried to make it work but with no luck so far. I read the documentation and saw that pressing the letters, closing and opening the keyboard called some asynchronous events. I don't know if we need to use the asynchronous events.
 

Nocturne

Friendly Tyrant
Forum Staff
Admin
Okay, there is a slight error in the docs and all input from the virtual keyboard is ONLY captured in the "keyboard_string" variable. Change your code to use that and is should all work... sorry about that and I'll get the docs fixed for the next updated.
 

gnysek

Member
Okay, there is a slight error in the docs and all input from the virtual keyboard is ONLY captured in the "keyboard_string" variable. Change your code to use that and is should all work... sorry about that and I'll get the docs fixed for the next updated.
Is keyboard_string cleared on keyboard_virtual_show(), or need to be done manually?
 
Thanks for the clarification! keyboard_string works but I'm going to need more help with this. I can't get the enter button on the virtual keyboard to respond.
Code:
if global.mobile
        {global.Name = keyboard_string 
        if [enter command] and string_length(global.Name)>=3)
            { do stuff }
Neither keyboard_key_press(vk_enter) or keyboard_lastkey=vk_enter work.
 

Mick

Member
Thanks for the clarification! keyboard_string works but I'm going to need more help with this. I can't get the enter button on the virtual keyboard to respond.
Code:
if global.mobile
        {global.Name = keyboard_string
        if [enter command] and string_length(global.Name)>=3)
            { do stuff }
Neither keyboard_key_press(vk_enter) or keyboard_lastkey=vk_enter work.
You should be able to check if last character of keyboard_string is '\r', according to this post: https://forum.yoyogames.com/index.p...eturn-key-has-been-pressed.51340/#post-314687
 
Thanks Mick, Just tested that on my android phone, and PC. It doesn't work on android or windows. Neither will reconize that.
 
That doesn't work either. Please test these things out on your own Computer, if we got back and forth like this it will make the thread unreadable.
 

Mick

Member
That doesn't work either. Please test these things out on your own Computer, if we got back and forth like this it will make the thread unreadable.
@Pfap might be able to help since he seems to have got it working. I don't have the time (nor will) to set up a project to test this at the moment.
 

rIKmAN

Member
That doesn't work either. Please test these things out on your own Computer, if we got back and forth like this it will make the thread unreadable.
Maybe he's posting on his phone to try and help you, or doesn't have time to test them himself?
Considering you made the thread asking for help maybe you shouldn't be so dismissive of someone offering suggestions which in no way make the thread unreadable.
 
I apologise. I didn't mean to be rude. You are right I am the one who asked. I have been testing all this stuff out, in addition to my own ideas, and while I'm happy for the help, I am afraid that if we just continue to go back and forth like this, it will be less likely someone will actually come in who will read through all this and help.
Mick if you or anyone else haves any other ideas you want to try I'll test them on android and PC.
 
So current status- I got the virtual keyboard working, but the submit button in the bottom right corner of the keyboard remains an elusive mystery.

If you want to have a virtual keyboard in your mobile game
Call keyboard_virtual_show(kbv_type_default,kbv_returnkey_default,kbv_autocapitalize_none,0) to bring it up
in the step event you can put some pretty simple code-
Code:
if keyboard_check_pressed(vk_anykey)
    {                  
         if string_length(global.Name)>stringmax  {keyboard_string  = string_copy(global.Name, 1, stringmax) };
         global.Name = keyboard_string;
    }
and then in the draw event draw global.Name
 

Pfap

Member
@Pfap might be able to help since he seems to have got it working. I don't have the time (nor will) to set up a project to test this at the moment.
I still have to try pushing it to xcode and I will probably get into Android in the coming weeks. But the \r does work for me on PC tests.

Code:
current_key = keyboard_lastchar;
//show_debug_message(current_key);
/*
maybe manually grab the last character of the keyboard_string by using string_length
and string copy? if it is "\r" it means the player pressed the return key 
do the above if the keyboard_lastchar does not work on ios 
*/

//13 should be the return key code and if the string is empty don't do anything
if current_key == "\r"{

//do stuff here you want to happen after the player has pressed enter

}
The above code needs to be in the step event; at least according to my tests as the keyboard events do not seem to work on mobile at least not ios… I need to test more.
 
As nocturne said current_key is not used in the virtual keyboard. You won't be able to use it to detect return.
You have to use keyboard_string to capture all virtual keyboard input
 

Pfap

Member
As nocturne said current_key is not used in the virtual keyboard. You won't be able to use it to detect return.
You have to use keyboard_string to capture all virtual keyboard input
Hmm.... hold on one second I'm going to push it to xcode. And current_key is my own variable I'm using it to store the built in keyboard variable keyboard_lastchar, but now I'm second guessing myself.
 

Pfap

Member
Ok, I did a bunch of tests on iOS and it seems that there is no way to directly check for the "return" (enter) key being pressed; although, I found an effective work around.

From the keyboard_string manual section:
This variable holds a string containing the last (at most) 1024 characters typed on the keyboard. This string will only contain printable characters typed, but it will correctly respond to pressing the backspace key by erasing the last character. This variable is not read only and you can change it, for example to set it to "" (an empty string) if you handled it already, or use the String Functions to manipulate it.
The reason "\n" works for space and "\r" works for enter on PC is because I could use the keyboard_lastchar which works with those escape characters.
So, when you tap enter it does not affect the keyboard_string at all. If keyboard_string == "User" and you hit enter keyboard_string == "User".

On iOS you can check for vk_any, but not vk_enter:

Code:
//step event




if keyboard_check_pressed(vk_anykey){
 //if hold_string5 == hold_string6 the strings are the same length and the player is probably tapping send
 switch(which_user_event){
 
  //case 5 will run first
  case 5:
 
  hold_string5 = keyboard_string;
  //alarm[5] = 30;
  event_user(5);
  showing = true;
  //reset the alarms so that the blinking resumes if not pressing
  alarm[0] = 30;
  alarm[1] = 0;
 
  break;
 
  case 6:
 
  hold_string6 = keyboard_string;
  //alarm[6] = 30;
  event_user(6);
  showing = true;
  //reset the alarms so that the blinking resumes if not pressing
  alarm[0] = 30;
  alarm[1] = 0;
 
  break;
 }
}

The "return" key is triggered by vk_any.


Basically just check every other key pressed and if hold_string6 == hold_string5 you know the user tapped enter or return.
 
While this workaround works, it's not a good solution to anything put through to production. We really need to have the various enter/return/done/etc. keys from the virtual keyboard map to vk_enter.
Worse part is that it's been two or three months since they've added the virtual keyboard functions. I can't believe Yoyo games hasn't done anything to fix this, smh...
 
Ok, I did a bunch of tests on iOS and it seems that there is no way to directly check for the "return" (enter) key being pressed; although, I found an effective work around.

From the keyboard_string manual section:


The reason "\n" works for space and "\r" works for enter on PC is because I could use the keyboard_lastchar which works with those escape characters.
So, when you tap enter it does not affect the keyboard_string at all. If keyboard_string == "User" and you hit enter keyboard_string == "User".

On iOS you can check for vk_any, but not vk_enter:

Code:
//step event




if keyboard_check_pressed(vk_anykey){
 //if hold_string5 == hold_string6 the strings are the same length and the player is probably tapping send
 switch(which_user_event){
 
  //case 5 will run first
  case 5:
 
  hold_string5 = keyboard_string;
  //alarm[5] = 30;
  event_user(5);
  showing = true;
  //reset the alarms so that the blinking resumes if not pressing
  alarm[0] = 30;
  alarm[1] = 0;
 
  break;
 
  case 6:
 
  hold_string6 = keyboard_string;
  //alarm[6] = 30;
  event_user(6);
  showing = true;
  //reset the alarms so that the blinking resumes if not pressing
  alarm[0] = 30;
  alarm[1] = 0;
 
  break;
 }
}

The "return" key is triggered by vk_any.


Basically just check every other key pressed and if hold_string6 == hold_string5 you know the user tapped enter or return.

I need help implementing this. I don't quite get how the switch statement would work or any of that. I just wish yoyo did something to fix this...
 

Pfap

Member
I need help implementing this. I don't quite get how the switch statement would work or any of that. I just wish yoyo did something to fix this...

This code checks the length of the keyboard_string every step and if it has not changed then it assumes the user tapped return. I am thinking there might be a way to have this functionality contained in just the step event, without the user events. The switch statement is just my way of having something fire every other time.


Create event:
Code:
which_event = 0;


hold_string = "";
hold_string1 = "";
Step event:
Code:
if keyboard_check_pressed(vk_anykey){

//the code in this block will only fire once per step if the user has pressed any key


 //if hold_string5 == hold_string6 the strings are the same length and the player is probably tapping send. This will be checked in the corresponding user events

 switch(which_event){
 
  case 0:
 
  hold_string = keyboard_string;
 
  event_user(0);
 
  break;
 
  case 1:
 
  hold_string1 = keyboard_string;
 
 
  event_user(6);

 
  break;
 }
}

User event 0
Code:
//next step case 1 will fire
which_alarm = 1;



show_debug_message(string_length(hold_string));
show_debug_message(string_length(hold_string1));

//if the strings are the same length it means nothing was added so assume they hit enter
if string_length(hold_string) == string_length(hold_string1){

//put any code that you would normal put in an enter event or run what you need to after the user hits return

}

User event 1
Code:
[/COLOR][/FONT][/LEFT][/COLOR][/FONT][/LEFT]
[FONT=arial][COLOR=rgb(222, 222, 222)]
[LEFT][FONT=arial][COLOR=rgb(222, 222, 222)]
[LEFT]
//next step case 0 will fire
which_alarm = 0;



show_debug_message(string_length(hold_string));
show_debug_message(string_length(hold_string1));

//if the strings are the same length it means nothing was added so assume they hit enter
if string_length(hold_string) == string_length(hold_string1){

//put any code that you would normal put in an enter event or run what you need to after the user hits return

}




The above should be able to be copied and pasted and work.

Just remove this stuff
[/COLOR][/FONT][/LEFT]


Not sure how to edit it out.


I am not the best teacher and I have the tendency to drone on, so if something is not clear please mention it specifically.
 
Last edited:
This code checks the length of the keyboard_string every step and if it has not changed then it assumes the user tapped return. I am thinking there might be a way to have this functionality contained in just the step event, without the user events. The switch statement is just my way of having something fire every other time.


Create event:
Code:
which_event = 0;


hold_string = "";
hold_string1 = "";
Step event:
Code:
if keyboard_check_pressed(vk_anykey){

//the code in this block will only fire once per step if the user has pressed any key


 //if hold_string5 == hold_string6 the strings are the same length and the player is probably tapping send. This will be checked in the corresponding user events

 switch(which_event){
 
  case 0:
 
  hold_string = keyboard_string;
 
  event_user(0);
 
  break;
 
  case 1:
 
  hold_string1 = keyboard_string;
 
 
  event_user(6);

 
  break;
 }
}

User event 0
Code:
//next step case 1 will fire
which_alarm = 1;



show_debug_message(string_length(hold_string));
show_debug_message(string_length(hold_string1));

//if the strings are the same length it means nothing was added so assume they hit enter
if string_length(hold_string) == string_length(hold_string1){

//put any code that you would normal put in an enter event or run what you need to after the user hits return

}

User event 1
Code:
[/COLOR][/FONT][/LEFT][/COLOR][/FONT][/LEFT][/COLOR][/FONT][/LEFT]
[FONT=arial][COLOR=rgb(222, 222, 222)]
[LEFT][FONT=arial][COLOR=rgb(222, 222, 222)]
[LEFT][FONT=arial][COLOR=rgb(222, 222, 222)]
[LEFT]
//next step case 0 will fire
which_alarm = 0;



show_debug_message(string_length(hold_string));
show_debug_message(string_length(hold_string1));

//if the strings are the same length it means nothing was added so assume they hit enter
if string_length(hold_string) == string_length(hold_string1){

//put any code that you would normal put in an enter event or run what you need to after the user hits return

}





The above should be able to be copied and pasted and work.

Just remove this stuff
[/COLOR][/FONT][/LEFT]


Not sure how to edit it out.


I am not the best teacher and I have the tendency to drone on, so if something is not clear please mention it specifically.
That is perfect thank you! From there I can keep working on this! Thanks! Anyways, I was checking for Android, and I saw that simply putting keyboard_check(10) does the trick to close the keyboard. I guess that is not working on apple devices right?
 

Pfap

Member
That is perfect thank you! From there I can keep working on this! Thanks! Anyways, I was checking for Android, and I saw that simply putting keyboard_check(10) does the trick to close the keyboard. I guess that is not working on apple devices right?
Glad I could help. You should be able to just call the function keyboard_virtual_hide();.
 
Hey guys, question: is there a way for the keyboard_string to add a "\n"? I'm trying to make the return key add a newline everytime it's pressed. However, it doesn't work the way I though it would(it's not working). Does yoyo not check before adding new functionality to the IDE? They also haven't fixed the keyboard_string resetting every step when the virtual keyboard is not active.
 
Top