diff --git a/README.md b/README.md index 496c4a6..eda5318 100644 --- a/README.md +++ b/README.md @@ -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. diff --git a/uinput.go b/uinput.go index f28caf9..a8c23e7 100644 --- a/uinput.go +++ b/uinput.go @@ -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 @@ -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)