Control mouse by writing to /dev/input/mice
this is not trough the file you mentioned, but its way quicker to use this tool instead of decypering the dump of that file. And it does everything you want in bash.
xdotool does the trick in my terminal.
this is the package site for ubuntu.
you probably can install it trough
# apt-get install xdotool
I could just emerge it on gentoo without adding any repositories.
the tool works fairly simple:
#! /bin/bash
# move the mouse x y
xdotool mousemove 1800 500
# left click
xdotool click 1
# right click
xdotool click 3
found it here
How do I simulate a single click on Windows and Linux using C?
On Windows, if you want to simulate a mouse click inside a specific window, the relevant window messages are the following (link to documentation included):
WM_LBUTTONDOWN
WM_LBUTTONUP
WM_LBUTTONDBLCLK (on second click, this message is sent instead of WM_LBUTTONDOWN)
To simulate a mouse click, you can send a window any of these window messages, using the PostMessage() function.
For this function, you require a window handle (HWND) for the target window. This can be obtained for example using the EnumWindows() or FindWindow() function.
However, if you want to simulate a mouse click on the screen instead of inside a specific window, then you will have to use the SendInput() function. For further details, see this Stack Overflow question.
Also, be aware that since Windows Vista, for security reasons, it is not possible anymore to send processes with administrative privileges messages from non-privileged processes.
The above information only applies to Windows. Unfortunately, I can't help you with Linux, but you may find the solution in this Stack Overflow question.
How can I control mouse movement in Linux?
Great thanks to R...
for reminding me of some other ways instead of /dev/psaux
I tried /dev/input/mouse*
and /dev/input/event*
By using
cat /proc/bus/input/devices
I get this:
I: Bus=0003 Vendor=0461 Product=4d81 Version=0111
N: Name="USB Optical Mouse"
P: Phys=usb-0000:00:1d.0-1/input0
S: Sysfs=/devices/pci0000:00/0000:00:1d.0/usb6/6-1/6-1:1.0/input/input10
U: Uniq=
H: Handlers=mouse2 event10
B: EV=17
B: KEY=70000 0 0 0 0 0 0 0 0
B: REL=143
B: MSC=10
After testing, only /dev/input/event10
works. The code is as follows:
#include <stdio.h>
#include <unistd.h>
#include <linux/input.h>
#include <errno.h>
#include <fcntl.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/time.h>
int main() {
struct input_event event, event_end;
int fd = open("/dev/input/event10", O_RDWR);
if (fd < 0) {
printf("Errro open mouse:%s\n", strerror(errno));
return -1;
}
memset(&event, 0, sizeof(event));
memset(&event, 0, sizeof(event_end));
gettimeofday(&event.time, NULL);
event.type = EV_REL;
event.code = REL_X;
event.value = 100;
gettimeofday(&event_end.time, NULL);
event_end.type = EV_SYN;
event_end.code = SYN_REPORT;
event_end.value = 0;
for (int i=0; i<5; i++) {
write(fd, &event, sizeof(event)); // Move the mouse
write(fd, &event_end, sizeof(event_end)); // Show move
sleep(1); // Wait
}
close(fd);
return 0;
}
Get mouse deltas using Python! (in Linux)
I'm on a basic device and not having access to X or ... so event.py doesn't works.
So here's my simpler decode code part to interpret from "deprecated" '/dev/input/mice':
import struct
file = open( "/dev/input/mice", "rb" );
def getMouseEvent():
buf = file.read(3);
button = ord( buf[0] );
bLeft = button & 0x1;
bMiddle = ( button & 0x4 ) > 0;
bRight = ( button & 0x2 ) > 0;
x,y = struct.unpack( "bb", buf[1:] );
print ("L:%d, M: %d, R: %d, x: %d, y: %d\n" % (bLeft,bMiddle,bRight, x, y) );
# return stuffs
while( 1 ):
getMouseEvent();
file.close();
Do GUI apps handle mouse signals directly from the device or they instead receive signals from the OS?
It's a very general question. What do you have in mind with it?
Very general, I would say: "it depends" - at least on the operating system, your app runs on and your mouse is connected to.
In all modern OSes, there's an abstraction layer (far away from any real circuits inside the computers hardware) that would make the answer to your question: they get the signals from the OS.
Related Topics
Using Assertion in the Linux Kernel
Differencebetween './Example.Sh' and 'Sh Example.Sh'
Linux Shell Script for Each File in a Directory Grab the Filename and Execute a Program
Convert All File Extensions to Lower-Case
Error with Gradlew: /Usr/Bin/Env: Bash: No Such File or Directory
Crontab Run Every 15 Minutes Between Certain Hours
Reliability of Linux Kernel Add_Timer at Resolution of One Jiffy
How Secure Is Storing Password with Git
Are Unix Reads and Writes to a Single File Atomically Serialized
Convert Utf8 to Utf16 Using Iconv
Determine If There Is Data Left on the Socket and Discard It
Shellscript to Monitor a Log File If Keyword Triggers Then Execute a Command
Output File Lines from Last to First in Bash
Postgresql -Bash: Psql: Command Not Found
How to Get Coordinates of Touchscreen Rawdata Using Linux
Command Not Found via Ssh with Single Command, Found After Connecting to Terminal