1. Hey! Guest! The XXX GMC Jam will take place between August 24th, 12:00 UTC (Friday noon) and August 27th, 12:00 UTC (Monday noon). Why not join in! Click here to find out more!
    Dismiss Notice

iOS How to check if the return key has been pressed?

Discussion in 'GameMaker Studio 2 Community Tech Support' started by Pfap, Aug 9, 2018.

  1. Pfap

    Pfap Member

    Joined:
    Apr 30, 2017
    Posts:
    265
    I have been playing around with the new virtual keyboard functions with ios and have noticed a few issues.

    I have an object that brings up the keyboard in the first room of my tests. It wasn't bringing the keyboard up, but there was some strange flicker in the default Gms2 splash screen, so I put an alarm in the objects create event and had the alarm bring the keyboard up and that worked fine.

    The main reason I made this post and I hope somebody has a solution is that the keyboard events don't seem to work with the virtual keyboard. I am specifically trying to check for when the user presses the return key and have tried the following.

    I checked the manual and I am not using predictive text.


    I tried checking keyboard_key to find the keycode and the built in variable keyboard_key does not work on ios.
    I figured the return code would be 13 and a quick web search does confirm this. The key press enter event does not work either. I also tried with the step event.







    Code:
    
    
    current_key = keyboard_key;
    
    
    //13 should be the return key and if the string is empty don't do anything
    if current_key == 13 && my_string != "" && click_once == true{
     
     
    
     show_debug_message("The return key has been pressed");
     click_once = false;
    
     
    }
    
    


    Any ideas?
     
  2. Mick

    Mick Member

    Joined:
    Jun 30, 2016
    Posts:
    644
    You should be able to check the last char of keyboard_string. If it's a new line character (\n), then return has been pressed. You should be able to clear keyboard_string manually once you have processed it, or just erase the new line character.

    I haven't tried the built in virtual keyboard myself, so there might be a better way.
     
  3. Pfap

    Pfap Member

    Joined:
    Apr 30, 2017
    Posts:
    265

    I got it working on the pc using (\r) I will post to this thread once I have tested on ios.
     
  4. Kurtis3

    Kurtis3 Member

    Joined:
    Aug 11, 2018
    Posts:
    2
    vk_enter ?
     
  5. studio furukawa

    studio furukawa Member

    Joined:
    Jun 22, 2016
    Posts:
    114
    I have the same problem, tried vk_enter and vk_return
     
  6. Pfap

    Pfap Member

    Joined:
    Apr 30, 2017
    Posts:
    265
    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.
     
  7. studio furukawa

    studio furukawa Member

    Joined:
    Jun 22, 2016
    Posts:
    114
    Good findings, but this is not good practice by yoyogames part. They just need to make a function called keyboard_virtual_return_pressed or map to vk_return, with proper documentation ofcourse. I don't see the reasoning behind setting rk_ in virtual keyboard without this.

    Edit: Pfap, what if a user presses Shift, Alt, Ctrl etc?
     
    Last edited: Aug 15, 2018 at 10:10 AM
  8. Pfap

    Pfap Member

    Joined:
    Apr 30, 2017
    Posts:
    265

    I'm not sure, which is kind of why I had this comment

    Code:
    if keyboard_check_pressed(vk_anykey){
    //if hold_string5 == hold_string6 the strings are the same length and the player is probably tapping send
    

    Edit:
    You could check if the other keyboard constants work. If it's only vk_enter that doesn't you could make statements that will only run if hold_string5 == hold_string6 && !vk_shift.
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice