How to make a sound every time you click something?

Moderators: 666philb, Forum moderators

Post Reply
bob93
Posts: 48
Joined: Fri Nov 25, 2022 8:29 am
Location: Fossapup64 9.5
Has thanked: 21 times
Been thanked: 1 time

How to make a sound every time you click something?

Post by bob93 »

Is it possible to have a custom sound play every time you press a mouse button? sort of like how games work. You click certain things on the interface and you hear a certain sound. You right click and you hear another.

If possible I'd like to hear a sound when I left click, and another when I right click. This kind of auditory feedback is very handy for screencasting

Fossapup64 9.5

User avatar
mikewalsh
Moderator
Posts: 5575
Joined: Tue Dec 03, 2019 1:40 pm
Location: King's Lynn, UK
Has thanked: 570 times
Been thanked: 1681 times

Re: How to make a sound every time you click something?

Post by mikewalsh »

@bob93 :-

Aye, it's certainly possible. I have a coupla scripts set-up, making use of MPlayer: one plays an "intro" sound at boot-up.....and the other plays the Win XP 'closing' jingle at shut-down.

It's simple enough to get the sound playing. The only thing I'm not at all certain about is how you get Puppy to 'detect' whenever a mouse button is clicked.....and thus trigger the audio script. Somebody here will know, but I wouldn't like to say who..... :?

Be patient. We'll sort summat out for ya..!

Certainly, this can be done for a 'global' rule for mouse behaviour. But from the sounds of it, you want this behaviour to ONLY occur when you're using specific programs?

============================

....later:-

(xev might be the way to go, then use xbindkeys to associate a particular key-press event with a given audio sound script? Did some reading on StackExchange, and this sounds like the easiest method for ID-ing a given button "event"...)

https://unix.stackexchange.com/question ... or-command

Info about xev/xbindkeys further down the page...

Just throwing this out there. "Me no expert", etc..! :D

Mike. ;)

Puppy "stuff" ~ MORE Puppy "stuff" ~ ....and MORE! :D
_______________________________________________________

Image

bob93
Posts: 48
Joined: Fri Nov 25, 2022 8:29 am
Location: Fossapup64 9.5
Has thanked: 21 times
Been thanked: 1 time

Re: How to make a sound every time you click something?

Post by bob93 »

mikewalsh wrote: Sat Mar 16, 2024 10:35 pm

Certainly, this can be done for a 'global' rule for mouse behaviour. But from the sounds of it, you want this behaviour to ONLY occur when you're using specific programs?

Not so much to have it only work while using certain programs, but to be able to turn it on and off whenever I want, if possible. Think of command

Code: Select all

xcalib -i -a

If you want to invert the screen colors you enter the command. When you're done you enter it again. Simple. It doesn't have to be done via a command but you get the idea

I'll check out that link. Thanks

Fossapup64 9.5

bob93
Posts: 48
Joined: Fri Nov 25, 2022 8:29 am
Location: Fossapup64 9.5
Has thanked: 21 times
Been thanked: 1 time

Re: How to make a sound every time you click something?

Post by bob93 »

Alright, I have given this a try using xbindkeys. First I had to create file /root/xbindkeysrc. Piece of cake
Then in that file I had to specify the command to play the file and the button associated with it, like this (b:1 is left mouse button, and I chose deadbeef because mplayer and mpv take a second to start playing. Deadbeef takes no time as long as it's already running):

Code: Select all

"deadbeef /root/Desktop/BUTTON.WAV"
 b:1

Then I killed and restarted xbindkeys. It works instantaneously just like I needed, but there's a problem: the mouse click only triggers the sound but the rest of system doesn't "see" the click, e.g. I click on any button on the screen and nothing happens except for the sound being played. This looks like an easy to solve common side-effect, so next I'm gonna look for how to allow the click to "go-through" to the system instead of being taken only by xbindkeys, then I think I'll be set.

I still leave this note here in case anyone knows the trick

Fossapup64 9.5

Tippe
Posts: 123
Joined: Wed Feb 15, 2023 11:55 pm
Has thanked: 7 times
Been thanked: 19 times

Re: How to make a sound every time you click something?

Post by Tippe »

Perhaps one can create something using xev.
Perhaps combined with xdotool.

Code: Select all

ButtonPress event, serial 36, synthetic NO, window 0x4400001,
    root 0x2b6, subw 0x0, time 2289790, (82,68), root:(217,230),
    state 0x10, button 1, same_screen YES

ButtonRelease event, serial 36, synthetic NO, window 0x4400001,
    root 0x2b6, subw 0x0, time 2289910, (82,68), root:(217,230),
    state 0x110, button 1, same_screen YES

Code: Select all

 echo `xev > /root/xev-ouput`

Bionic Puppy 64bit.
Won't use another one.

bob93
Posts: 48
Joined: Fri Nov 25, 2022 8:29 am
Location: Fossapup64 9.5
Has thanked: 21 times
Been thanked: 1 time

Re: How to make a sound every time you click something?

Post by bob93 »

Alright, I asked around and a xbindkeys expert gave me this tip:

You have to prevent xbindkeys to grab the key before replaying the mouse click.

Something like this should do the trick :

"pkill xbindkeys; sleep 0.1; xdotool click 1; play sound.mp3 & xbindkeys"
b:1

This is a little bit inefficient but should work.

Now, this looks like a shorthand description of a command, but how would it actually look like in a terminal/text file?

Fossapup64 9.5

User avatar
rockedge
Site Admin
Posts: 5715
Joined: Mon Dec 02, 2019 1:38 am
Location: Connecticut,U.S.A.
Has thanked: 1995 times
Been thanked: 2097 times
Contact:

Re: How to make a sound every time you click something?

Post by rockedge »

Looking at xbindkeys it could look like this in script form

Code: Select all

#!/bin/sh

pkill xbindkeys
sleep 0.1
xdotool click 1
play sound.mp3 & 
xbindkeys
b:1
User avatar
MochiMoppel
Posts: 1116
Joined: Mon Jun 15, 2020 6:25 am
Location: Japan
Has thanked: 17 times
Been thanked: 359 times

Re: How to make a sound every time you click something?

Post by MochiMoppel »

bob93 wrote: Tue Apr 30, 2024 2:55 pm

Alright, I asked around and a xbindkeys expert gave me this tip:

You have to prevent xbindkeys to grab the key before replaying the mouse click.
Something like this should do the trick :
"pkill xbindkeys; sleep 0.1; xdotool click 1; play sound.mp3 & xbindkeys"
b:1

This is a little bit inefficient but should work.

Now, this looks like a shorthand description of a command, but how would it actually look like in a terminal/text file?

It works. The red lines are the lines you have to use in your .xbindkeysrc file. The play sound.mp3 is just an example of the audio command and your expert used the play command instead of your deadbeef , which may be a bit less inefficient ;)

Running the commands from a bash script as @rockedge proposed didn't work for me.

User avatar
rockedge
Site Admin
Posts: 5715
Joined: Mon Dec 02, 2019 1:38 am
Location: Connecticut,U.S.A.
Has thanked: 1995 times
Been thanked: 2097 times
Contact:

Re: How to make a sound every time you click something?

Post by rockedge »

@MochiMoppel the bash script doesn't work for me either. Added to the .xbindkeysrc the command string works.

Post Reply

Return to “Fossapup64”