How to simulate touch events - c#

I am working on a touch application using Kinect's depth sensor.
I am able to get the points where the user puts it's fingers, but I'd like to fire the corresponding Touch events.
For example, i'd like to be able to send TouchDown, Touch Up, Touch Move events.
I took a look at TouchDevice and TouchPoint classes, but I don't see how I should do this. I tried to create a fake TouchPoint and added it to a custom TouchDevice, but I don't know what to do next.
I tried to do a ReportDown but it only fires Touch_FrameReported with empty arguments.
So my question is, how do one fires the touch system events ? Is it possible with these classes, or should I go with windows messages (WM_TOUCH and WM_GESTURE) ?

Related

Swipe cause GetMouseButtonDown(0)

I have a script that recognizes swiping input. When I now start a swipe, it also triggers Input.GetMouseButtonDown(0). Can you tell me how to delete Input.GetMouseButtonDown(0) that comes from the swipe?
With that swipe the game gets paused. (with Time.timeScale = 0f;)
After resume, the action which was triggered from Input.GetMouseButtonDown(0) before pausing the game goes on.
My Ideas: Work with TouchPhase.Stationary or look for short tap?
Off the top of my head, you can either:
Call Input.ResetInputAxes; it will clear all input flags for one frame.
Set a flag that a swipe was handled, and check for it when checking for Input.GetMouseButtonDown(0) elsewhere.
Both will require ensuring that the swipe detection happens before you check for Input.GetMouseButtonDown(0).
One way of ensuring it, is by using Unity's script execution order settings.
I would recommend not using Input class at all, it causes many problems, better have separate RaycastTarget on UI with Script implementing IPointerDownHandler, IPointerUpHandler, that will ensure only one RaycastTarget at the moment is handling your touches. Input.GetMouseButton will return true even if some RaycastTarget already should have consumed your events.

How to initiate click to activate code in Unity 3D?

I am designing a shooting game in Unity 3d for which I have a requirement that only when an image is tapped the shooting should occur. Please check the command used for the purpose:
if (Input.GetMouseButtonDown(0)){
if (!clickedConfirmed){
GameObjectClicked = GetClickedGameObject();
clickedConfirmed = true;
}
Currently, shooting occurs when clicked anywhere on the screen. How can activation of shooting be bonded only to the gameobject (image) instead of being activated when clicked anywhere on the screen.
Your need to give more context in your example, especially what GetClickedGameObject() is actually doing internally.
As such I'm limited in what I can say is the problem, but I suspect that you aren't using GameObjectClicked correctly.
I would expect that you'd do a check such as:
this.gameObject == GameObjectClicked
Note that if this being used as a method of developing a UI there are more elegant solutions out there, including the long awaited new GUI system included in the Unity3d 4.6 open beta.

Processing game input

So my basic 2d game framework in SlimDX is going well. I've created a custom Sprite object, and have some rudimentary mastery of rendering sprites. I just need to move them now.
I have a basic game loop set up, which is based on an old C# game programming book. Having set up all the graphics device bits and bobs, and drawn my sprite on screen, I enter a method in my Game class called Run(). This has the following content:
public void Run()
{
while( this.Created )
{
// Process one frame of the game
ProcessFrame();
Render();
// Handle all events
Application.DoEvents();
}
}
ProcessFrame() is supposed to have all the game logic in it, in response to events. Whilst I have a simple event handler (based on an override of OnKeyDown) set up to detect keypresses, I'm wondering how to collect keypresses such that I can process the responses to them in the ProcessFrame() method.
Some initial research on this subject suggests creating a HashSet<Keys>. I've never done this before, so I'm not sure how I would go about it.
There are probably many ways to do this, so I thought I'd see what people would recommend before jumping right in there.
Thanks in advance everyone.
I don't believe you need to manually capture inputs. This typically would be handled by the direct input keyboard class. I personally have not used SlimDX myself yet but as it is a wrapper for DirectX (which I've dabbled in) you should just need to initialize a variable to hold the reference to the keyboard so that you can poll it for changes, and then act upon those changes.
http://slimdx.org/docs/#T_SlimDX_DirectInput_Keyboard
Such that you would code something like
if (myKeyboard.IsKeyDown(Keys.Escape)) { ProgramStatus = GameState.Title; }
assuming my reference variable was called myKeyboard.
Edit:
I might also mention that depending on the particular library your using that it can be beneficial to save current, and previous keyboard states. This is very useful when you want to ensure that the program only takes in one keystroke vs many.
XNA as I recall has a KEYDOWN method for controllers, useful to test if the button is being held down. If you need to take in a input for each time the button is hit capture both.
IE if your library has a Keypress method, your good, if it captures KEYDOWN only you may need to capture current and previous.
if (myMouse.LeftButton == ButtonState.Pressed && oldMouse.LeftButton == ButtonState.Released)

Capture Kinect event to a scatterViewItem

I'm attempting to adapt a MSSurface application to allow use of a Kinect. Using the code4fun libraries, I'm able to generate an event from the Kinect when a user puts their hand towards the screen, but what I'm missing is how to trigger a ScatterViewItem's touch or click event to grab item, and then release it once finished moving. from the kinect skeleton model I can get adjusted x/y co-ordinates which i could apply if I can trap the right events in the ScatterViewItem.. And code suggestions would be appreciated...
regards,
Rob
If you are just looking to move the item, the easiest thing is to set the ScatterViewItem's Center property to the translated x/y coordinates. You can then control when the item is 'grabbed' fairly easily using whatever conditions you want.
If you are also after pinch/zoom, you'll have to do some playing around. Since the Kinect doesn't have the resolution to detect the fingers pinching and zooming, you could implement this by mapping the Z coordinate of the hand to preset sizes on the grabbed ScatterViewItem.

Suppress mouse-movement

I need to freeze the windows mouse cursor on the screen, so it stays hovered over a specific UI element. While the mouse is in this frozen state, I would still like to be able to interact with the UI using a "fake" mouse pointer.
Currently, I've got a low level mouse hook that prevents WM_MOUSEMOVE messages from being passed along, effectively stopping all real mouse movement. However, when I don't pass along the updated coordinates, windows actually sends me the old coordinates in a separate WM_MOUSEMOVE message, as if to correct for the fact that the mouse didn't move.
Any idea on either how to prevent Windows from sending me these corrected coordinates, or another approach of how I can freeze the actual mouse curosr and still allow the physical mouse to control a "Fake" cursor?
You can suppress mouse cursor movement by using DirectInput exclusive mode.
You should acquire mouse input device when cursor movement must be suppressed. This will block windows cursor movement but you can get messages for your fake cursor using DirectInput API.
If you move the mouse cursor position in response to a WM_MOUSEMOVE message, to put the mouse back to where you want it, you will get another mouse move message because the mouse has been moved again (because you moved it). To stop this, don't set the mouse position if it is already in the right place.
You may also want to clip the mouse position to your window and get exclusive access to it.
Why don't you just draw an image of the cursor at the place you want it frozen, then set the real mouse cursor to be hidden (Cursor.Hide IIRC).
It's not clear to me what you are trying to do, perhaps making a tutorial for your app and you want to show mouse movements, etc. Perhaps this library will be useful:
http://www.codeproject.com/KB/system/globalmousekeyboardlib.aspx

Categories

Resources