Skip to content
This repository has been archived by the owner on Mar 19, 2024. It is now read-only.

Commit

Permalink
Fix uinput backward compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
bendahl committed May 10, 2023
1 parent 350c651 commit 6001012
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 44 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,9 @@ Also, thanks to @sheharyaar there is now a new function `FetchSyspath()` that re

2023-04-27: Release 1.6.1 fixes uinput functionality on Wayland. Thanks to @gslandtreter for this fix and for pointing out the relevant piece of documentation!

2023-05-10: Release 1.6.2 fixes uinput an issue introduced in version 1.6.1 that will break backward compatibility. The change will be reverted for now.
Options to improve compatibility with newer systems are being evaluated. Thanks to @wenfer for the hint!

TODO
----
The current API can be considered stable and the overall functionality (as originally envisioned) is complete.
Expand Down
86 changes: 42 additions & 44 deletions uinput.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,73 +6,71 @@ are part of this package ("Key1" for number 1, for example).
In order to use the virtual keyboard, you will need to follow these three steps:
1. Initialize the device
Example: vk, err := CreateKeyboard("/dev/uinput", "Virtual Keyboard")
1. Initialize the device
Example: vk, err := CreateKeyboard("/dev/uinput", "Virtual Keyboard")
2. Send Button events to the device
Example (print a single D):
err = vk.KeyPress(uinput.KeyD)
2. Send Button events to the device
Example (print a single D):
err = vk.KeyPress(uinput.KeyD)
Example (keep moving right by holding down right arrow key):
err = vk.KeyDown(uinput.KeyRight)
Example (keep moving right by holding down right arrow key):
err = vk.KeyDown(uinput.KeyRight)
Example (stop moving right by releasing the right arrow key):
err = vk.KeyUp(uinput.KeyRight)
Example (stop moving right by releasing the right arrow key):
err = vk.KeyUp(uinput.KeyRight)
3. Close the device
Example: err = vk.Close()
3. Close the device
Example: err = vk.Close()
A virtual mouse input device is just as easy to create and use:
1. Initialize the device:
Example: vm, err := CreateMouse("/dev/uinput", "DangerMouse")
1. Initialize the device:
Example: vm, err := CreateMouse("/dev/uinput", "DangerMouse")
2. Move the cursor around and issue click events
Example (move mouse right):
err = vm.MoveRight(42)
2. Move the cursor around and issue click events
Example (move mouse right):
err = vm.MoveRight(42)
Example (move mouse left):
err = vm.MoveLeft(42)
Example (move mouse left):
err = vm.MoveLeft(42)
Example (move mouse up):
err = vm.MoveUp(42)
Example (move mouse up):
err = vm.MoveUp(42)
Example (move mouse down):
err = vm.MoveDown(42)
Example (move mouse down):
err = vm.MoveDown(42)
Example (trigger a left click):
err = vm.LeftClick()
Example (trigger a left click):
err = vm.LeftClick()
Example (trigger a right click):
err = vm.RightClick()
3. Close the device
Example: err = vm.Close()
Example (trigger a right click):
err = vm.RightClick()
3. Close the device
Example: err = vm.Close()
If you'd like to use absolute input events (move the cursor to specific positions on screen), use the touch pad.
Note that you'll need to specify the size of the screen area you want to use when you initialize the
device. Here are a few examples of how to use the virtual touch pad:
1. Initialize the device:
Example: vt, err := CreateTouchPad("/dev/uinput", "DontTouchThis", 0, 1024, 0, 768)
2. Move the cursor around and issue click events
Example (move cursor to the top left corner of the screen):
err = vt.MoveTo(0, 0)
1. Initialize the device:
Example: vt, err := CreateTouchPad("/dev/uinput", "DontTouchThis", 0, 1024, 0, 768)
Example (move cursor to the position x: 100, y: 250):
err = vt.MoveTo(100, 250)
2. Move the cursor around and issue click events
Example (move cursor to the top left corner of the screen):
err = vt.MoveTo(0, 0)
Example (trigger a left click):
err = vt.LeftClick()
Example (move cursor to the position x: 100, y: 250):
err = vt.MoveTo(100, 250)
Example (trigger a right click):
err = vt.RightClick()
Example (trigger a left click):
err = vt.LeftClick()
3. Close the device
Example: err = vt.Close()
Example (trigger a right click):
err = vt.RightClick()
3. Close the device
Example: err = vt.Close()
*/
package uinput

Expand Down Expand Up @@ -139,7 +137,7 @@ func createUsbDevice(deviceFile *os.File, dev uinputUserDev) (fd *os.File, err e
_ = deviceFile.Close()
return nil, fmt.Errorf("failed to write user device buffer: %v", err)
}
err = ioctl(deviceFile, uiDevSetup, uintptr(unsafe.Pointer(buf)))
_, err = deviceFile.Write(buf.Bytes())
if err != nil {
_ = deviceFile.Close()
return nil, fmt.Errorf("failed to write uidev struct to device file: %v", err)
Expand Down

0 comments on commit 6001012

Please sign in to comment.