Jump to content


Photo

Keyboard string no caps


  • Please log in to reply
4 replies to this topic

#1 dasrkrain

dasrkrain

    GMC Member

  • GMC Member
  • 176 posts
  • Version:GM:Studio

Posted 26 December 2011 - 06:13 AM

Can someone please help me out with this. I am using keyboard_string to get a players name, but it does not detect caps in html5! I don't know how to go about fixing this and I can't find any other posts on this topic.
  • 0

#2 jimn346

jimn346

    GMC Member

  • GMC Member
  • 422 posts

Posted 27 December 2011 - 06:01 PM

Try this.

Create
namestr = "";
keyboard_string = "";

Step
if (string_length(keyboard_string) > 0)
  {
  if (keyboard_check(vk_shift)
    namestr += string_upper(keyboard_string);
  else
    namestr += keyboard_string;
  keyboard_string = "";
  }
if (keyboard_check_pressed(vk_backspace) && string_length(namestr) > 0)
  namestr = string_copy(namestr, 0, string_length(namestr) -1);

  • 0

#3 dasrkrain

dasrkrain

    GMC Member

  • GMC Member
  • 176 posts
  • Version:GM:Studio

Posted 30 December 2011 - 07:26 AM

Try this.

Create

namestr = "";
keyboard_string = "";

Step
if (string_length(keyboard_string) > 0)
  {
  if (keyboard_check(vk_shift)
    namestr += string_upper(keyboard_string);
  else
    namestr += keyboard_string;
  keyboard_string = "";
  }
if (keyboard_check_pressed(vk_backspace) && string_length(namestr) > 0)
  namestr = string_copy(namestr, 0, string_length(namestr) -1);



I was just about to build something like that when I decided to come check and see if anyone had a better solution, but now that I see it written out it looks really good! Thanks you very much jimn346!
  • 0

#4 dasrkrain

dasrkrain

    GMC Member

  • GMC Member
  • 176 posts
  • Version:GM:Studio

Posted 30 December 2011 - 08:13 AM

okay so after some playing around with the code I was able to come up with this...

if (keyboard_check_pressed(20))   //check if caps is on
{
    if caps = 0 //if caps is off
    {
        caps=1;     //turn caps on
    }
    else    //if caps is on
    {
        caps=0; //turn caps off
    }
}

if (string_length(keyboard_string) > 0)     //if keys are being pressed
{
    if caps=1   //if caps is on
    {
        name += string_upper(keyboard_string);  //any key pressed is uppercase
    }
    else    //if caps is off
    {
        name += keyboard_string;    //any key pressed is lower case
    }
    keyboard_string = "";       //then reset keyboard string
}

if (keyboard_check_pressed(vk_backspace) && string_length(name) > 0) //if a letter is deleted
{
    name = string_copy(name, 1, string_length(name) -1);    //delete the letter from the string
}

and it works pretty well for me!
  • 0

#5 darkclower

darkclower

    GMC Member

  • New Member
  • 80 posts
  • Version:GM8

Posted 14 April 2012 - 09:05 PM

okay so after some playing around with the code I was able to come up with this...

if (keyboard_check_pressed(20))   //check if caps is on
{
    if caps = 0 //if caps is off
    {
        caps=1; 	//turn caps on
    }
    else    //if caps is on
    {
        caps=0; //turn caps off
    }
}

if (string_length(keyboard_string) > 0) 	//if keys are being pressed
{
    if caps=1   //if caps is on
    {
        name += string_upper(keyboard_string);  //any key pressed is uppercase
    }
    else    //if caps is off
    {
        name += keyboard_string;    //any key pressed is lower case
    }
    keyboard_string = "";   	//then reset keyboard string
}

if (keyboard_check_pressed(vk_backspace) && string_length(name) > 0) //if a letter is deleted
{
    name = string_copy(name, 1, string_length(name) -1);    //delete the letter from the string
}

and it works pretty well for me!



Wouldn't that just ignore if caps is on or off before you start the game? But the code looks great besides from that.
  • 0




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users