playMaker

Author Topic: Get Any Key Store Result as String  (Read 18609 times)

FractalCore

  • 1.2 Beta
  • Full Member
  • *
  • Posts: 100
Re: Get Any Key Store Result as String
« Reply #15 on: October 09, 2013, 04:12:18 AM »
Now, I wonder if justifun made the action on a Mac in the first place, and if he tested it recently on PC...

After testing it by playing builds (only way to get it working), I made a very handy little text input system. All the letters/numbers/symbols of course, got backspace erasing one letter back at a time. Saved as a string to use anywhere else. All thanks to this Action. It should really be included as standard.

justifun

  • 1.2 Beta
  • Sr. Member
  • *
  • Posts: 280
Re: Get Any Key Store Result as String
« Reply #16 on: October 09, 2013, 05:49:24 AM »
@FractalCore - nope, it was made on a PC.  It was just a copy of the "Any Key" action with a line added to store the result.



jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Get Any Key Store Result as String
« Reply #17 on: October 09, 2013, 05:52:47 AM »
Hi,

 ok, I'll try on windows side when I have a chance

bye,

 Jean

FractalCore

  • 1.2 Beta
  • Full Member
  • *
  • Posts: 100
Re: Get Any Key Store Result as String
« Reply #18 on: October 15, 2013, 04:31:44 PM »
Have you had a chance to try this on Windows yet. It would be interesting if it didn't work for you too.

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Get Any Key Store Result as String
« Reply #19 on: October 16, 2013, 02:45:57 AM »
Hi,

 Yes, I just tried, and indeed in editor, it's weird! but when I publish it's all fine and works as expected... I also tested without PlayMaker being involved and it's the same...

Bye,

 Jean

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Get Any Key Store Result as String
« Reply #20 on: October 16, 2013, 03:00:31 AM »
Hi,

 Ok, I found a way to solved this. I use Input.AnyKey instead of Input.AnyKeyDown and it works now everywhere including windows editor.

Please find attached the update version. I am not overwriting cause the behavior is slighlty different, you will get repeated input if you keep the key pressed, which is logical in a way.

MABManZ

  • 1.2 Beta
  • Full Member
  • *
  • Posts: 125
    • MABManZ.com
Re: Get Any Key Store Result as String
« Reply #21 on: October 21, 2013, 04:12:30 PM »
Thanks so much Jean it looks like everything is good!

joduffy

  • Full Member
  • ***
  • Posts: 121
  • Here to help
    • Online Playmaker Courses
Re: Get Any Key Store Result as String
« Reply #22 on: April 26, 2014, 07:00:44 AM »
Hi guys,

I am testing this on a windows 7 machine 64 bit and getting nothing stored into the string. It doesnt store when i click the mouse button or keyboard keys.

Is there something I am doing wrong
- Jonathan

Online Playmaker Courses available at:
http://courses.jonathanoduffy.com

“I want the world to be a better place because I was here.”  -  Will Smith

joduffy

  • Full Member
  • ***
  • Posts: 121
  • Here to help
    • Online Playmaker Courses
Re: Get Any Key Store Result as String
« Reply #23 on: April 26, 2014, 07:24:05 AM »
I did find this:

http://issuetracker.unity3d.com/issues/input-dot-inputstring-works-differently-on-windows-and-on-mac

The other option is to try something like this:

Event.isKey

bool isKey;
Description
Is this event a keyboard event? (Read Only)

using UnityEngine;
using System.Collections;

public class Example : MonoBehaviour {
    void OnGUI() {
        Event e = Event.current;
        if (e.isKey)
            Debug.Log("Detected a keyboard event!");
       
    }
}

But this belongs in the OnGUI. Not sure how to access it from a custom playmaker script.

http://docs.unity3d.com/Documentation/ScriptReference/Event.html
- Jonathan

Online Playmaker Courses available at:
http://courses.jonathanoduffy.com

“I want the world to be a better place because I was here.”  -  Will Smith

joduffy

  • Full Member
  • ***
  • Posts: 121
  • Here to help
    • Online Playmaker Courses
Re: Get Any Key Store Result as String
« Reply #24 on: April 29, 2014, 01:53:35 AM »
I wrote a C# to store the results of a key press. This excludes mouse events/buttons/actions.

You access the results via a get property action in a FSM and store it in a FSMString.

You can also use the script to trigger an event in a playmaker FSM by giving the name of the event to send and also the FSM in which the event lives. This is done in the inspector panel.

I have attached the script and also displayed the code below.

Code: [Select]
// (c) Copyright HutongGames, LLC 2010-2013. All rights reserved.

using UnityEngine;

namespace HutongGames.PlayMaker.Actions
{
[ActionCategory(ActionCategory.Input)]
[Tooltip("Sends an Event when a Key is released.")]
public class GetKeyUpFromString : FsmStateAction
{
[RequiredField]
public FsmString key;
public FsmEvent sendEvent;
[UIHint(UIHint.Variable)]
public FsmBool storeResult;

public override void Reset()
{
sendEvent = null;
//key.Value = KeyCode.None;
storeResult = null;
}

public override void OnUpdate()
{
bool keyUp = Input.GetKeyUp(key.Value);

if (keyUp)
Fsm.Event(sendEvent);

storeResult.Value = keyUp;
}
}
}
- Jonathan

Online Playmaker Courses available at:
http://courses.jonathanoduffy.com

“I want the world to be a better place because I was here.”  -  Will Smith

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Get Any Key Store Result as String
« Reply #25 on: June 03, 2014, 08:08:09 AM »
Hi,

 Is that action working on windows phones then?

Bye,

 Jean

LogLady

  • Full Member
  • ***
  • Posts: 150
Re: Get Any Key Store Result as String
« Reply #26 on: January 16, 2015, 12:31:16 PM »
I used the example that jeanfabre made on this topic but the backspace is not working. It is not deleting the last typed character. Is there a way to make it work?

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Get Any Key Store Result as String
« Reply #27 on: January 19, 2015, 01:40:59 AM »
Hi,

 Are you using the new UI system? I think fields will work a LOT better then with other solutions.  Catching keys manually seems odd on windows unfortunatly.

 Bye,

 Jean

LogLady

  • Full Member
  • ***
  • Posts: 150
Re: Get Any Key Store Result as String
« Reply #28 on: January 20, 2015, 10:25:57 AM »
Maybe that is the problem. I'm using windows 7 and the pressed keys (as said before on this topic) only blinks. I hope that the Unity guys can solve it sometime...