LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Hardware > Linux - Embedded & Single-board computer
User Name
Password
Linux - Embedded & Single-board computer This 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


Reply
  Search this Thread
Old 12-14-2021, 05:56 AM   #1
rjlee
Senior Member
 
Registered: Jul 2004
Distribution: Ubuntu 7.04
Posts: 1,994

Rep: Reputation: 76
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?
 
Old 12-15-2021, 12:39 PM   #2
boughtonp
Senior Member
 
Registered: Feb 2007
Location: UK
Distribution: Debian
Posts: 3,624

Rep: Reputation: 2556Reputation: 2556Reputation: 2556Reputation: 2556Reputation: 2556Reputation: 2556Reputation: 2556Reputation: 2556Reputation: 2556Reputation: 2556Reputation: 2556

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?

Alternatively, Ncurses mouse events looks simple enough to deal with?

 
1 members found this post helpful.
Old 12-15-2021, 02:36 PM   #3
rjlee
Senior Member
 
Registered: Jul 2004
Distribution: Ubuntu 7.04
Posts: 1,994

Original Poster
Rep: Reputation: 76
Quote:
Originally Posted by boughtonp View Post
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.

Quote:
Originally Posted by boughtonp View Post
Alternatively, Ncurses mouse events looks simple enough to deal with?
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).
 
Old 12-15-2021, 02:53 PM   #4
dugan
LQ Guru
 
Registered: Nov 2003
Location: Canada
Distribution: distro hopper
Posts: 11,249

Rep: Reputation: 5323Reputation: 5323Reputation: 5323Reputation: 5323Reputation: 5323Reputation: 5323Reputation: 5323Reputation: 5323Reputation: 5323Reputation: 5323Reputation: 5323
Quote:
Originally Posted by boughtonp View Post
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...

https://www.linuxquestions.org/quest...1/#post6287133

An inotify watch on the mouse device would work too.

Last edited by dugan; 12-15-2021 at 02:55 PM.
 
1 members found this post helpful.
Old 12-15-2021, 06:32 PM   #5
rclark
Member
 
Registered: Jul 2008
Location: Montana USA
Distribution: KUbuntu, Fedora (KDE), PI OS
Posts: 496

Rep: Reputation: 182Reputation: 182
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.
 
1 members found this post helpful.
Old 12-15-2021, 07:05 PM   #6
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,781

Rep: Reputation: 5935Reputation: 5935Reputation: 5935Reputation: 5935Reputation: 5935Reputation: 5935Reputation: 5935Reputation: 5935Reputation: 5935Reputation: 5935Reputation: 5935
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.
 
1 members found this post helpful.
Old 12-20-2021, 05:52 AM   #7
rjlee
Senior Member
 
Registered: Jul 2004
Distribution: Ubuntu 7.04
Posts: 1,994

Original Poster
Rep: Reputation: 76
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.
 
  


Reply

Tags
button, event, hotkey, mouse, usb



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Cannot sequentially press Alt key then menu accelerator, must press both concurrently Woodsman Slackware 1 03-21-2013 03:21 PM
how to check the status of mouse-button/ a key press in linux using C ? 001spidy Linux - Newbie 4 06-26-2011 12:14 AM
How to make mid-mouse button send key press to application utahnix Linux - Software 2 10-09-2007 05:14 PM
LXer: http://www.clusterresources.com/pages/press/press-releases.php LXer Syndicated Linux News 0 04-12-2006 07:21 AM
middle mouse button is paste.. but what if i dont have a mid mouse button? kublador Linux - Newbie 4 09-02-2003 08:59 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Hardware > Linux - Embedded & Single-board computer

All times are GMT -5. The time now is 12:07 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration