[SOLVED] How best to signal a URL when I press a mouse (or other) button?
Linux - Embedded & Single-board computerThis forum is for the discussion of Linux on both embedded devices and single-board computers (such as the Raspberry Pi, BeagleBoard and PandaBoard). Discussions involving Arduino, plug computers and other micro-controller like devices are also welcome.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
How best to signal a URL when I press a mouse (or other) button?
What I'd like to do is to POST to a URL when I press a physical button, using an embedded Linux system that doesn't have X. I have an old USB mouse that I could repurpose for this (rewiring the buttons).
I'm working on a home automation project. I have a networked single-board computer (QNAP TS-210) running Linux, with a USB port but no current peripherals, and I want to provide physical switches to send signals to my outbuilding.
The problem isn't the network access, it's with detecting the button press.
I could do this with coding: Without a physical terminal, I don't think a new gpm client would work. But I think I could probably hack the gpm server to call a script when it sees a mouse event, and get it to run on the raw console before login somehow.
I was wondering if there was an easier way to get a windowless mouse hotkey handler than writing code?
Not sure if I understand what you want - are you basically asking if anyone knows of a tool like sxhkd (Simple X hotkey daemon) but without requiring X, so you don't have to write one yourself?
In the absence of any answers to that... how complicated is it to write what you need? I would assume it's basically just a simple loop that polls /dev/input/mouse0 or something?
If not, can you look at however X listens to the kernel events and extract the relevant parts?
Not sure if I understand what you want - are you basically asking if anyone knows of a tool like sxhkd (Simple X hotkey daemon) but without requiring X, so you don't have to write one yourself?
Yes; this would solve my problem. I'd also accept another hardware solution to accept a physical input switch to do the same thing.
Thank you for this; I have used ncurses before, but not the mouse library, so I hadn't even thought of that possibility; I think that would be the simplest answer - assuming I can get the program to run on the login tty.
In the old days, I'd just hook the switch up to the parallel port and register an interrupt handler, but that seems to be impossible on a PC without a bespoke GPIO (general purpose I/O) header. I guess modern PCs (even single-board ones) are too complex to handle something as simple as a switch (perhaps for reasons of security).
In the absence of any answers to that... how complicated is it to write what you need? I would assume it's basically just a simple loop that polls /dev/input/mouse0 or something?
Incidentally, I've posted some sample code here...
Also, since you have USB available, you could always talk directly to a little board (rather than a mouse) that provides any physical I/O you may want to hook up. A board such as the RP2040 ItsyBitsy . As long as you have USB you have lots of options to get some I/O into your system whether a full blown PC or a SBC like an RPI4 (which has GPIO built in)! Of course there will be a tiny bit of coding to make it work.
With the teensy you could simulate a USB keyboard and have a mechanical switch send a keyboard code. Of course you need to learn how to program the device.
Not sure what else you are doing with the QNAP but it might be cheaper and easier using a Pi Zero in the long run.
I'd hoped to avoid using another general purpose computer, but it looks like it's going to be far easier to use a single board PC with GPIO pins to do the job. Thanks all.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.