Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice

How to Intercepting KeyDown event on Q10 device

Discussion in 'BlackBerry' started by pgarcia, Oct 10, 2013.

  1. pgarcia

    pgarcia

    Joined:
    Sep 21, 2013
    Posts:
    7
    I'm playing around a game where you have to type things, but not using a UI textbox. On desktop I could accomplish it using the OnGUI event handler like below:

    Code (csharp):
    1. void OnGUI() {
    2.         ev = Event.current;
    3.         if(ev != null) {
    4.             if (ev.isKey){
    5.                if(ev.type == EventType.KeyDown){
    6.                     if (ev.shift)
    7.                         shiftPressed = true;
    8.                     else
    9.                         shiftPressed = false;
    10.                     char c = ev.character;
    11.   (...)
    12. }
    13.  
    My problem is that, on keyboard-based devices like the Q10, the event KeyDown is not generated when typing using the physical keyboard. I wonder if this is the right approach or if I should be using something else. I know if I use Input.GetKeyDown() I can test specific keys, but I need to get anything...

    My objective is to get everything that could be typed using the keyboard (all characters, backspace, etc...)

    Any idea?

    Thanks in advance!


    Paulo
     
  2. pgarcia

    pgarcia

    Joined:
    Sep 21, 2013
    Posts:
    7
    I did few more tests using Input.anyKey in the Update() function. With that, I could see the Q10 still doesn't get anything. The weird part was that if I start to press several keys very fast, some of the characters will be detected, but most of them won't.

    It seems to me there is a bug with the BB player when using the Q10. I've filed a report, but this is a bit frustrating since there is no simple solution.

    Anyone has a better idea about what to do?

    Thanks

    Paulo
     
  3. AlexThibodeau

    AlexThibodeau

    Unity Technologies

    Joined:
    Jul 23, 2013
    Posts:
    309
    Hrm... I'll have to look into that.

    When I was looking into this particular issue originally I was fetching the keys pressed like so:

    Code (csharp):
    1.     void detectKeysPressed()
    2.     {  
    3.         var values = Enum.GetValues(typeof(KeyCode));
    4.         foreach(KeyCode keyVal in values)
    5.         {
    6.             if(Input.GetKeyDown(keyVal))
    7.             {
    8.                 keyspressed = keyVal.ToString();
    9.             }
    10.         }
    11.     }
    That I know works 100% of the time. What's the case number for the bug you submitted?
     
  4. pgarcia

    pgarcia

    Joined:
    Sep 21, 2013
    Posts:
    7
    Hi Alex,

    I will try to do like you did, but even if it works, is it as efficient as using the Input.anyKey (if it works) ?

    THe bug I filed is case # 568778.

    Thanks

    Paulo
     
  5. AlexThibodeau

    AlexThibodeau

    Unity Technologies

    Joined:
    Jul 23, 2013
    Posts:
    309
    AnyKey would be more efficient of detecting any button presses. My code is useful for determining which key is pressed and that KeyCodes can be used in conjunction with GetKeyDown or GetKey to determine when specific buttons are being pressed on the Q10.

    However, you did find a bug! I poked through the code and found that I was not setting the generic shift value to true when LShift or RShift is pressed. I will be queuing this up in my list of things to fix. :)
     
    Last edited: Oct 11, 2013
  6. pgarcia

    pgarcia

    Joined:
    Sep 21, 2013
    Posts:
    7
    Awesome! I'm glad I could help. Also, you code is working for me and I can keep going with my project using it for now.

    Thanks for the support

    Paulo