Decoding Key Values from /dev/input/eventx in C closed Ask Question. Browse other questions tagged c devices input-devices events ascii or ask your own question.
Apr 21, 2017 /dev/input – The input is a subdirectory that holds the device files for various input devices such as mouse, keyboard, joystick and so on. This is a screenshot of my input directory and as you can see there is the mice/mouse0/mouse1 which are files corresponding to the touchpad/wired mouse/wireless mouse respectively. It gives me the code, type, and value of the event when it occurs. I also can't rework the whole system to listen to a different device. Ideally, I need to work with just /dev/input/eventX without adding/changing/reworking any existing drivers or devices.
-->- Enables the mouse to act as a pointing device. GetCapture: Retrieves a handle to the window (if any) that has captured the mouse. Only one window at a time can capture the mouse; this window receives mouse input whether or not the cursor is within its borders. GetDoubleClickTime: Retrieves the current double-click time for the mouse.
- The Input object is responsible for converting input from the player into data in a form Actors can understand and make use of. Unreal Engine 4 Documentation Gameplay Guide Input Input.
- 1 The input protocol uses a map of types and codes to express input device values 2 to userspace. This document describes the types and codes and how and when they 3 may be used. 4 5 A single hardware event generates multiple input events. Each input event 6 contains the new value of a single data item.
Receive, process, and manage input data from pointing devices (such as touch, mouse, pen/stylus, and touchpad) in your Universal Windows Platform (UWP) applications.
Important
Create custom interactions only if there is a clear, well-defined requirement and the interactions supported by the platform controls don't support your scenario.
If you customize the interaction experiences in your Windows application, users expect them to be consistent, intuitive, and discoverable. For these reasons, we recommend that you model your custom interactions on those supported by the platform controls. The platform controls provide the full Universal Windows Platform (UWP) user interaction experience, including standard interactions, animated physics effects, visual feedback, and accessibility.
If you customize the interaction experiences in your Windows application, users expect them to be consistent, intuitive, and discoverable. For these reasons, we recommend that you model your custom interactions on those supported by the platform controls. The platform controls provide the full Universal Windows Platform (UWP) user interaction experience, including standard interactions, animated physics effects, visual feedback, and accessibility.
Important APIs
Pointers
Most interaction experiences typically involve the user identifying the object they want to interact with by pointing at it through input devices such as touch, mouse, pen/stylus, and touchpad. Because the raw Human Interface Device (HID) data provided by these input devices includes many common properties, the data is promoted and consolidated into a unified input stack and exposed as device-agnostic pointer data. Your UWP applications can then consume this data without worrying about the input device being used.
Note
Device-specific info is also promoted from the raw HID data should your app require it.
Each input point (or contact) on the input stack is represented by a Pointer object exposed through the PointerRoutedEventArgs parameter in the various pointer event handlers. In the case of multi-pen or multi-touch input, each contact is treated as a unique input pointer.
Pointer events
Pointer events expose basic info such as input device type and detection state (in range or in contact), and extended info such as location, pressure, and contact geometry. In addition, specific device properties such as which mouse button a user pressed or whether the pen eraser tip is being used are also available. If your app needs to differentiate between input devices and their capabilities, see Identify input devices.
UWP apps can listen for the following pointer events:
Note
Constrain pointer input to a specific UI element by calling CapturePointer on that element within a pointer event handler. When a pointer is captured by an element, only that object receives pointer input events, even when the pointer moves outside the bounding area of the object. The IsInContact (mouse button pressed, touch or stylus in contact) must be true for CapturePointer to be successful.
Event | Description |
---|---|
Occurs when a pointer is canceled by the platform. This can occur in the following circumstances:
| |
Occurs when another UI element captures the pointer, the pointer was released, or another pointer was programmatically captured. Note There is no corresponding pointer capture event. | |
Occurs when a pointer enters the bounding area of an element. This can happen in slightly different ways for touch, touchpad, mouse, and pen input.
| |
Occurs when a pointer leaves the bounding area of an element. This can happen in slightly different ways for touch, touchpad, mouse, and pen input.
| |
Occurs when a pointer changes coordinates, button state, pressure, tilt, or contact geometry (for example, width and height) within the bounding area of an element. This can happen in slightly different ways for touch, touchpad, mouse, and pen input.
| |
Occurs when the pointer indicates a press action (such as a touch down, mouse button down, pen down, or touchpad button down) within the bounding area of an element. CapturePointer must be called from the handler for this event. | |
Occurs when the pointer indicates a release action (such as a touch up, mouse button up, pen up, or touchpad button up) within the bounding area of an element or, if the pointer is captured, outside the bounding area. | |
Occurs when the mouse wheel is rotated. Mouse input is associated with a single pointer assigned when mouse input is first detected. Clicking a mouse button (left, wheel, or right) creates a secondary association between the pointer and that button through the PointerMoved event. |
Pointer event example
Here are some code snippets from a basic pointer tracking app that show how to listen for and handle events for multiple pointers, and get various properties for the associated pointers.
Download this sample from Pointer input sample (basic)
Create the UI
For this example, we use a Rectangle (
Target
) as the object consuming pointer input. The color of the target changes when the pointer status changes.Details for each pointer are displayed in a floating TextBlock that follows the pointer as it moves. The pointer events themselves are reported in the RichTextBlock to the right of the rectangle.
This is the Extensible Application Markup Language (XAML) for the UI in this example.
Dev C++ Download
Listen for pointer events
In most cases, we recommend that you get pointer info through the PointerRoutedEventArgs of the event handler.
If the event argument doesn't expose the pointer details required, you can get access to extended PointerPoint info exposed through the GetCurrentPoint and GetIntermediatePoints methods of PointerRoutedEventArgs.
The following code sets up the global dictionary object for tracking each active pointer, and identifies the various pointer event listeners for the target object.
Handle pointer events
Next, we use UI feedback to demonstrate basic pointer event handlers.
- This handler manages the PointerPressed event. We add the event to the event log, add the pointer to the active pointer dictionary, and display the pointer details.NotePointerPressed and PointerReleased events do not always occur in pairs. Your app should listen for and handle any event that might conclude a pointer down (such as PointerExited, PointerCanceled, and PointerCaptureLost).
- This handler manages the PointerEntered event. We add the event to the event log, add the pointer to the pointer collection, and display the pointer details.
- This handler manages the PointerMoved event. We add the event to the event log and update the pointer details.ImportantMouse input is associated with a single pointer assigned when mouse input is first detected. Clicking a mouse button (left, wheel, or right) creates a secondary association between the pointer and that button through the PointerPressed event. The PointerReleased event is fired only when that same mouse button is released (no other button can be associated with the pointer until this event is complete). Because of this exclusive association, other mouse button clicks are routed through the PointerMoved event.
- This handler manages the PointerWheelChanged event. We add the event to the event log, add the pointer to the pointer array (if necessary), and display the pointer details.
- This handler manages the PointerReleased event where contact with the digitizer is terminated. We add the event to the event log, remove the pointer from the pointer collection, and update the pointer details.
- This handler manages the PointerExited event (when contact with the digitizer is maintained). We add the event to the event log, remove the pointer from the pointer array, and update the pointer details.
- This handler manages the PointerCanceled event. We add the event to the event log, remove the pointer from the pointer array, and update the pointer details.
- This handler manages the PointerCaptureLost event. We add the event to the event log, remove the pointer from the pointer array, and update the pointer details.NotePointerCaptureLost can occur instead of PointerReleased. Pointer capture can be lost for various reasons including user interaction, programmatic capture of another pointer, calling PointerReleased.
Get pointer properties
As stated earlier, you must get most extended pointer info from a Windows.UI.Input.PointerPoint object obtained through the GetCurrentPoint and GetIntermediatePoints methods of PointerRoutedEventArgs. The following code snippets show how.
- First, we create a new TextBlock for each pointer.
- Then we provide a way to update the pointer info in an existing TextBlock associated with that pointer.
- Finally, we query various pointer properties.
Primary pointer
Some input devices, such as a touch digitizer or touchpad, support more than the typical single pointer of a mouse or a pen (in most cases as the Surface Hub supports two pen inputs).
Use the read-only IsPrimary property of the PointerPointerProperties class to identify and differentiate a single primary pointer (the primary pointer is always the first pointer detected during an input sequence).
By identifying the primary pointer, you can use it to emulate mouse or pen input, customize interactions, or provide some other specific functionality or UI.
Note
C++ Read Dev Input Event
If the primary pointer is released, canceled, or lost during an input sequence, a primary input pointer is not created until a new input sequence is initiated (an input sequence ends when all pointers have been released, canceled, or lost).
Primary pointer animation example
These code snippets show how you can provide special visual feedback to help a user differentiate between pointer inputs in your application.
This particular app uses both color and animation to highlight the primary pointer.
Download this sample from Pointer input sample (UserControl with animation)
Visual feedback
Dev C++ Programs
We define a UserControl, based on a XAML Ellipse object, that highlights where each pointer is on the canvas and uses a Storyboard to animate the ellipse that corresponds to the primary pointer.
Here's the XAML:
And here's the code-behind:
Create the UI
The UI in this example is limited to the input Canvas where we track any pointers and render the pointer indicators and primary pointer animation (if applicable), along with a header bar containing a pointer counter and a primary pointer identifier.
Here's the MainPage.xaml:
Handle pointer events
Finally, we define our basic pointer event handlers in the MainPage.xaml.cs code-behind. We won't reproduce the code here as the basics were covered in the previous example, but you can download the working sample from Pointer input sample (UserControl with animation).
Related articles
Topic samples
Other samples
Archive samples