0

I have a gesture recognition software. I want to perform a click by calling Input.GetButtonDown("Fire1") when user waves his hand. Right now I have:

    public void Wave(){
    if(waving code){
    Debug.Log("user waved");
    Input.GetButtonDown("Fire1");
    }
   }

The "user waved" log shows just fine but the click is not performed. If anybody can help me with that or suggest an alternative, I would appreciate it.

3
  • answers.unity.com/questions/945299/… Commented Jun 25, 2018 at 3:41
  • @Aybe Thank you! Although it looks like your answer is related to a function clicking on a determined button. What im trying to do is essentially replace a cursor. User can move the mouse and once he waves his hand, whichever button is underneath will be clicked. Any ideas how to do that? Thank you! Commented Jun 25, 2018 at 5:09
  • You want to simulate mouse from code, right ? If so then I see mouse_event or SendInput on Windows. You'll have to p/invoke a bit, it's quite easy. Commented Jun 25, 2018 at 5:26

2 Answers 2

1

The problem here is that

Input.GetButtonDown("Fire1");

is bool method not an event. So in order to fix it I suggest you to try this solution:

  1. Download zip file on: http://inputsimulator.codeplex.com
  2. Unzip that to Assets directory with Your script (C#) in Unity project
  3. Reload MonoDevelop (if is openend)
  4. In script on top write: using WindowsInput;
  5. and ... in class You can use this for example: InputSimulator.SimulateKeyPress (VirtualKeyCode.RIGHT); //simulate right arrow press

Good luck, I hope this helps.

Sign up to request clarification or add additional context in comments.

Comments

1

The Input.GetButtonDown method checks if a button is down. It seems you've assumed it tells the program to act as though a button has been pressed, which is not the case.

I think are more fundamental aspect is why you are trying to emulate a click? Surely it would be simpler to get the position info of the gesture and act accordingly?

4 Comments

I didnt know that Input.GetButtonDown was a boolean, thank you for that! I'm not sure what you mean by "Surely it would be simpler to get the position info of the gesture and act accordingly?". As I mentioned in another comment what im trying to do is essentially emulate a cursor click. User can move the mouse and once he waves his hand, whichever button is underneath will be clicked. I have the waiving code which if put in if statement can execute other code: like changing fonts, colors etc. But Im trying to make it emulate a mouse click rather than a one predefined code.
I don't think emulating a mouse click is the best way to solve the problem. Obviously I can't see exactly what you are doing, but to me it seems more logical to leave out the click altogether? What do you want to happen when the user gestures to click?
Literally to jut emulate the click haha. For example there is a virtual keyboard, if the cursor is above "T" and user waves, I want the computer to type "T" and so on.
Ok, so hijacking the mouse click is one option. However, the other option is make a fake cursor object, and when you call its "Click()" function it will perform the appropriate action depending on what it is hovering over. I'll leave it to your discretion as to what path you take.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.