How to set long press normal mouse triggers?

Hi,

I'm trying to set up my generic bluetooth mouse so that the side buttons (3 and 4) have multiple uses depending on whether they're long or short pressed. I've searched through the forums, but can't find whether it's possible to do so.

I had such a setup using Mac Mouse Fix, but BTT is much more useful overall, so I'd prefer to replicate that and only use the one app.

Unfortunately the long keypress feature has not been ported over to mouse buttons.

I rolled my own...

Mouse button down, Run Real JavaScript...

(async ()=> {
	function to() {
		(async ()=> {
			var downTime = await callBTT('get_number_variable', {variable_name: 'button-downtime'});
			if (downTime === thisTime) {
				callBTT('trigger_named_async_without_response', {trigger_name: 'Button X long click'});
				setTimeout(to, 500);
			}
		})();
	}

	var thisTime = Date.now();
	callBTT('set_number_variable', {variable_name: 'button-downtime', to: thisTime});
	setTimeout(to, 250);
	returnToBTT(0);
})();

Mouse button up, Run Real JaveScript...

(async ()=> {
	var thisTime = Date.now();
	var downTime = await callBTT('get_number_variable', {variable_name: 'button-downtime'});

	if (downTime !== undefined && downTime !== -1 && thisTime - downTime < 250)
		callBTT('trigger_named_async_without_response', {trigger_name: 'Button X short click'});

	callBTT('set_number_variable', {variable_name: 'button-downtime', to: -1});
	returnToBTT(downTime);
})();

Tweak the 'button3-downtime' variable name to ensure you have unique names for each button, and adjust the 'trigger_name' for your prefered action.

2 Likes

Integrated long press for mouse buttons will soon be available in BTT, but for now this solution is great!

2 Likes

Many thanks for your help!

:edit: Sorry to be a pain, but can you talk me through this process? I'm a complete novice here, so have no idea how to make this work...