How can I perform a simulated key, only when pressing two buttons at the same time ?

x64 Replacement/Alternative to Microsoft's IntelliMouse application.
Forum rules
Please read the forum rules before posting for the first time.
The more information you can provide, the quicker and more accurately someone can help.
NOTE: To reduce spam, new users can not post links, files or images until they have at least 4 posts.
Post Reply
shodan
New User
Posts: 10
Joined: Tue Feb 13, 2024 5:22 am

How can I perform a simulated key, only when pressing two buttons at the same time ?

Post by shodan »

Please fill in this template when posting!
XMBC Version: 2.20.5
Installed or Portable version: installed
Windows Version:
Edition Windows 10 Pro
Version 22H2
OS build 19045.3930
Experience Windows Feature Experience Pack 1000.19053.1000.0
Mouse Information (brand/model):
logitech mx master 3s
Relevant Computer Information (CPU, RAM etc):
Did the problem occur after an upgrade of XMBC? (If so, from what version?):
Did the problem occur after a Windows update/upgrade? (If so, from what version?):
How long have you used XMBC?:
year long
What language and keyboard layout do you use in Windows?:
english I think en_uk but windows always hides where the keyboard layout is and I can't find it !
Clear description of the problem - try and include as much information as possible, including what button and mappings you are having problems with (if applicable).:

Hi,

So, in my previous message, I figured out how to simulated a keypress on BUTTONUP rather than BUTTONDOWN.

The reason I want to do this is that when I press a button and hold, not do that action until I release.
BUT, if instead of release I press another mouse button, I want to send a different keypress !

Here is my full situation.


I have a profile for firefox.exe

mouse button 4 -> simlated keys (pressed) -> {ACTIVATE}{CTRL}{PGUP}
mouse button 5 -> simlated keys (pressed) -> {ACTIVATE}{CTRL}{PGDN}

So how this works is

When I press mouse 4 or mouse 5, it will go to previous or next tab. Works great, I love it, can't use a computer without it !

Now I what I want to do is, press mouse 4 and hold, then press mouse 5 and it should send CTRL+W which closes the current tab, now release and it should NOT send "{ACTIVATE}{CTRL}{PGUP}"

I should be able, while holding down mouse 4, to press mouse 5 several times to send several CTRL+W.

I would also like to press mouse 5, hold it, then press mouse 4 to do the same thing (maybe ? or maybe that would be another action ?)

Now, extra crazy would be ... I have the amazing app AltSnap installed.

Could I press and hold mouse 4, nothing happens, I press and hold mouse 1 but my computer things I'm alt+mouse1 dragging. That'd be awesome !


How can I do this ?
shodan
New User
Posts: 10
Joined: Tue Feb 13, 2024 5:22 am

Re: How can I perform a simulated key, only when pressing two buttons at the same time ?

Post by shodan »

I asked ChatGPT, here is what it said, I'm going to try it !


Hello shodan,

What you're looking to achieve – having a mouse button perform a different action when pressed in combination with another button – is a bit more complex but definitely possible with some creative configuration in XMBC. Unfortunately, XMBC doesn't directly support "chording" (pressing two buttons simultaneously for a new action) in a straightforward manner, but we can work around this with some scripting or layer toggling.

For your specific request, you'll need to use simulated keys and possibly layer switching to achieve the desired effect. Here's a step-by-step guide that might help:
  • Layer Toggling: First, you'll need to set up a new layer in XMBC where the button mappings are different. You can toggle to this layer when one button is held down.

    Button 4 Configuration:
    On your default layer, configure button 4 to switch to a new layer (let's call it "Layer 2") when pressed and held. In "Layer 2", button 4 can be configured to do nothing on press but switch back to the default layer on release. This way, releasing button 4 without pressing button 5 will result in no action.

    Button 5 Configuration on Layer 2:
    On "Layer 2", configure button 5 to send the CTRL+W command on press. Ensure it's set to switch back to the default layer upon release if button 4 is not being held down anymore.

    Handling Button 5 then Button 4:
    For pressing button 5 and then button 4, you will need to replicate the layer switch logic but in reverse. This might be a bit more complex, as it requires the software to recognize the sequence. If XMBC cannot support this natively, you might need to look into a more advanced scripting solution or third-party macro software that supports chording.

    Advanced Functionality with AltSnap:
    Integrating AltSnap actions (like alt+mouse1 dragging) might be achievable by setting up another layer specifically for AltSnap actions and using simulated key presses to mimic the Alt+Drag functionality. This would involve a similar layer toggling approach where holding mouse 4 switches to an "AltSnap layer" where mouse 1 is mapped to Alt+Drag.
Remember, the key to making this work is the layer switching functionality in XMBC, which allows you to temporarily change the button mappings based on the state of other buttons. You may need to experiment with the settings and possibly use the "During" option in the simulated keys to ensure the command is executed as long as the button is held down.

Since this setup can get quite complex, I recommend trying to set up one piece of functionality at a time and testing thoroughly before moving on to the next. Also, keep an eye on the XMBC forum and documentation for any updates or new features that might make this process easier.

Hope this helps, and happy tweaking!
User avatar
phil
Site Admin
Posts: 7670
Joined: Sun Apr 06, 2003 11:12 pm

Re: How can I perform a simulated key, only when pressing two buttons at the same time ?

Post by phil »

ChatGPT may be using out of date information there.
You might want to look at button chording instead (even if the GhatGPT method works).

Button chording allows you to chord two buttons to perform different actions. XMBC has supported that for quite some time now (at least 5 years), despite what ChatGPT said!

For scenario 1, button choring on button 4, default (no chord action) for button 4 in the chord setup, sim keys, {ACTIVATE}{CTRL}{PGUP} as before.
Simkeys for button 5 in the chord config: {ACTIVATE}{CTRL}{PGDN}

If you want it to work both ways, setup the chord appropriately (in reverse) on button 5.

NOTE: You have several options to control how the chord works/is released, including based on movement.

For the alt+drag...
In the button 4 chord, just set button 1 to change movement to scroll.
But of course, you still have button 4 no chrod action set to your simkeys, so if you press and hold button 4, do nothing and release button 4, it will, eventully send the simkeys in no chord. I'm not sure there is any way to prevent that currently (like there is no way to say only send the default/no chord if then button is held down for more than / less than Xms).
--[ Phil ]--
--[ Administrator & XMBC Author ]--
Logitech G9/G604/M720/MX518, Microsoft Intellimouse, Trust 16341 BT Mouse
Windows 10 x64, AMD Ryzen 5900x, MSI x570 Tomahawk, 32GB DDR4,
nVidia RTX 2070s, Evo 970 1Tb NVME, 2x2TB WD Black (RAID1)
shodan
New User
Posts: 10
Joined: Tue Feb 13, 2024 5:22 am

Re: How can I perform a simulated key, only when pressing two buttons at the same time ?

Post by shodan »

I got it working yesterday.

I just did my first organic tab close with this method, it felt pretty good !!

Here's how I set it up

http ://i imgur com/CMYoCt9.png

So firefox profile

Button 5 : chording : button 4 (released) chord simulate {activate}{ctrl}w , (released) no chording {activate}{ctrl}{pgup}
Disabled unblock when mouse moves
Disable unblock after timer

If I press mouse 5 and release, does ctrl+page down
If I press mouse 5 then mouse 4, does ctrl+w, will do another on every mouse 4 until I release mouse 5 and does not ctrl+page down when I release mouse 5
And it sends that to the window under my cursor.
I can hold mouse 5 indefinitely, doesn't do anything until I press or release something else.

Perfect !

Now I'm really curious to see if I can make AltSnap work with this, it would be an amazing combo.

AltSnap is a program that lets you move or resize a window from anywhere on that window, if you left click and hold it while pressing alt.

So I'm curious to make it "press alt" if I chord mouse 5 + left click to do a alt+leftclickdrag, is that possible ?
User avatar
phil
Site Admin
Posts: 7670
Joined: Sun Apr 06, 2003 11:12 pm

Re: How can I perform a simulated key, only when pressing two buttons at the same time ?

Post by phil »

I think so, don't see why not... you wont be able to use "sticky left button [click drag]" because it wont send the alt.
On the left button try sim keys, and method 3 (during): {alt}{LMB}
That should do it... You will have to try it and see if it works (I am at work right now so cant test it here) it should be OK but if not let me know.
--[ Phil ]--
--[ Administrator & XMBC Author ]--
Logitech G9/G604/M720/MX518, Microsoft Intellimouse, Trust 16341 BT Mouse
Windows 10 x64, AMD Ryzen 5900x, MSI x570 Tomahawk, 32GB DDR4,
nVidia RTX 2070s, Evo 970 1Tb NVME, 2x2TB WD Black (RAID1)
shodan
New User
Posts: 10
Joined: Tue Feb 13, 2024 5:22 am

Re: How can I perform a simulated key, only when pressing two buttons at the same time ?

Post by shodan »

I tried like this, but it does not trigger.

http ://i imgur com yYmojzp.png

default profile mouse 5 chord -> left button -> sim key -> {activate}{alt} with disable block original input

I checked to see if mouse 5 press prevents alt-drag but it does not. I can alt+leftclick+mouse5+drag it works the same as alt+leftclick+drag

It is bed time and too tired to think of another way. I will give this a shot again tomorrow, it would be a game changer to altsnap with the mouse, there are so so many features built in to altsnap.

Really wish I could make alt function work with the thumb button of my mx master 3s but without installing the terrible logitech software ! But mouse5 would still be awesome.
shodan
New User
Posts: 10
Joined: Tue Feb 13, 2024 5:22 am

Re: How can I perform a simulated key, only when pressing two buttons at the same time ?

Post by shodan »

Found these threads

viewtopic.php?t=1262

viewtopic.php?t=573

viewtopic.php?t=2726

And I managed this

https://youtu.be/jKgvT217nDw

So turning a mouse button into ALT works great, works with all AltSnap mouse action sweet !

Then I tried to only press ALT with chording of left click but could not figure it out yet !

Will try again tomorrow !
shodan
New User
Posts: 10
Joined: Tue Feb 13, 2024 5:22 am

Re: How can I perform a simulated key, only when pressing two buttons at the same time ?

Post by shodan »

I have figured it out

It is amazing !

demo

https://www.youtube.com/watch?v=4Yq4ar7KuX0

default
mouse button 5 -> button chording -> default -> no change
disable block original button
mouse button 5 -> button chording -> left button -> simulate key (during) -> {ACTIVATE}{ALT}{LMB}
mouse button 5 -> button chording -> right button -> simulate key (during) -> {ACTIVATE}{ALT}{RMB}
mouse button 5 -> button chording -> middle button -> simulate key (during) -> {ACTIVATE}{ALT}{MMB}

firefox profile
mouse button 4 -> simulate key (during) -> {ACTIVATE}{CTRL}{PGUP}
mouse button 5 -> button chording -> default -> simulate key (release) -> {ACTIVATE}{CTRL}{PGUP}
mouse button 5 -> button chording -> left button -> simulate key (during) -> {ACTIVATE}{ALT}{LMB}
mouse button 5 -> button chording -> right button -> simulate key (during) -> {ACTIVATE}{ALT}{RMB}
mouse button 5 -> button chording -> middle button -> simulate key (during) -> {ACTIVATE}{ALT}{MMB}
mouse button 5 -> button chording -> mouse 4 -> simulate key (release) -> {ACTIVATE}{CTRL}W
User avatar
phil
Site Admin
Posts: 7670
Joined: Sun Apr 06, 2003 11:12 pm

Re: How can I perform a simulated key, only when pressing two buttons at the same time ?

Post by phil »

That sounds good - its quite a complex configuration you have there, I not sure even I fully understand it, but glad you have got it working for your needs!

PS. I will be away on vacation (in Quebec) for a while, so further replies may be quite delayed (or maybe quicker if I'm in your timezone!)
--[ Phil ]--
--[ Administrator & XMBC Author ]--
Logitech G9/G604/M720/MX518, Microsoft Intellimouse, Trust 16341 BT Mouse
Windows 10 x64, AMD Ryzen 5900x, MSI x570 Tomahawk, 32GB DDR4,
nVidia RTX 2070s, Evo 970 1Tb NVME, 2x2TB WD Black (RAID1)
shodan
New User
Posts: 10
Joined: Tue Feb 13, 2024 5:22 am

Re: How can I perform a simulated key, only when pressing two buttons at the same time ?

Post by shodan »

If you find yourself near 4201 Rue de Verdun, Verdun, QC H4G 1L4 , I recommend you get a poutine and a toasted hot dog there. The poutine there is delicious. It is not a touriste poutine, just a very good, normal one. It is a very working class, ordinary place but I go there every time I traverse the city when I visit my mom in the north ! Anyway....

I was surprised this forum, there had never been a mention of AltSnap ! It goes so well with xbmc !

https://github.com/RamonUnch/AltSnap

It is a continuation of AltDrag, the original big feature is that it allows you to move a window by left-clicking anywhere on it, not just the titlebar, by pressing alt while you do it.

In the current version, you can also alt right click to resize a window from anywhere and alt middle click to get a menu of actions to perform, like kill, maximize, always on top. etc..

Also, alt-scroll can make any window transparent

So my setup is that basically to enable all the ALT features, but with the alternative of using Mouse 5

The previous thing is, to go back and forth in the firefox tab bar with mouse4 mouse5 and close tab with mouse4+mouse5 chord

I've been doing the ctrl+page up/down for a while now and it worked great. But now I just added the close tab chord.

This key combo works in other tabbed applications, like Excel, Gajim and Notepad++

However, I notice minor glitches with "Mouse 5 as ALT" function. Not sure exactly what I'm doing wrong, but sometimes, the button or maybe ALT gets stuck on. pressing many buttons eventually unsticks it. I will need more experience with this setup to sus out this problem !
shodan
New User
Posts: 10
Joined: Tue Feb 13, 2024 5:22 am

Re: How can I perform a simulated key, only when pressing two buttons at the same time ?

Post by shodan »

Hi,

I have been working this setup since last time.

It works, it works all the time but there is one major problem.

I am getting alt or mouse button stuck

I'm not sure if that's a xbmc issue or a altsnap issue, but even though it the function works when I try it, having keys getting stuck randomly is too disruptive to use for me.

So what happens is, I will do an "alt drag" with mouse5+leftdrag or an "alt resize" with mouse5+rightdrag and it will work.
But then my next click sometimes doesn't work.

I'm not sure if that's because I "mouse up" while outside the window, or inside the window, or because I let go of mouse5 before or after the other button.

Often, I end up re-doing the action, like a mouse5+click maybe, and it will unstick the key.

I'm not sure if it is the mouse button getting stuck, or the alt button getting stuck.

To re-iterate here is my xmbc config

default
firefox_tA3KLiBGbR.png
firefox
firefox_HK3DWAVXeu.png


And to explain

by default

Pressing Mouse 5, does not do anything
but if chorded with left, right and middle buttons, it will activate the page under the cursor and simulate an alt+mouseclick that button
the "during" directive, I think, should release the alt and the button when I let go

In the firefox profile, it is the same thing however

Mouse 4 simulates a CTRL+page up (previous tab in firefox)
Mouse 5 simulates a CTRL+page down (next tab in firefox) but only on mouse up (released directive) and only if there was not a chord
Mouse 5 + Mouse 4 simulates a CTRL+W, which is close tab

I block original mouse button on both the chord and on the simulated key.

I tried not blocking chord and left mouse button, but this did not change anything.

I tried removing {LMB} while not blocking the key, and alt+drag stopped working, it seems to need the simulated {LMB} even if the button is not blocked

I played with it some more, and it seems when I do mouse5+leftdrag, when I let go, the next left click will be a "stuck click" is the best way I can describe it. I find this reliably happens.


I have created a short video screenshot demonstration this issue

https://youtu.be/MupIqqv-yWs
You do not have the required permissions to view the files attached to this post.
User avatar
phil
Site Admin
Posts: 7670
Joined: Sun Apr 06, 2003 11:12 pm

Re: How can I perform a simulated key, only when pressing two buttons at the same time ?

Post by phil »

I wonder if you could try the latest beta, its had a years worth of development since 2.20.5 and several things have been fixed and added. I would hate to spend a long time investigating this to find out I have fixed it already :)). However, I'm not sure I have fixed it already (if indeed it it is a problem in XMBC itself - probably!) but starting from the same point would make things easier. The beta version also has more debug logging (which may be useful to capture is you can reproduce this reliably).

The best thing to do regarding capturing the issue with the debug logging, is to setup a global hotkey to toggle debug logging ON/OFF. Then when the key/button gets stuck, turn on debug logging, and then turn it back off again. This will flush the last 200 lines of debug log to the log file - which means it wound fill the log with lots of irrelevant stuff, and should produce just the stuff around the time it went wrong. Then send me a copy of the log file (and tell me the rough time it went wrong)! The log may be useful to see what is going on (again, it may not be enough, but hopefully it will).

I have to say, I see the occasional stuck key or mouse button. Certainly with the mouse buttons I suspect XMBC is at play, and I think particularly chording, which is quite a complex state to manage and keep track of, but not so much with the stuck keys (that is when I'm using the keyboard and not the mouse - so I *don't think* XMBC is involved). It is annoying though, whatever causes it.

If you find yourself near 4201 Rue de Verdun, Verdun, QC H4G 1L4 , I recommend you get a poutine and a toasted hot dog there. The poutine there is delicious. It is not a touriste poutine, just a very good, normal one. It is a very working class, ordinary place but I go there every time I traverse the city when I visit my mom in the north ! Anyway....
I missed that message until now - shame, as I was in Montreal for two days at the end of the trip - although quite far from there so I probably wouldn't have got there. Lovely city though so I will probably be back at some point. Had a bit of a nightmare - we went to snowmobile (around Mont Laurier) but had difficulty finding enough snow - did manage it eventually going further north, but had to cancel all booked stuff and re-arrange!)
--[ Phil ]--
--[ Administrator & XMBC Author ]--
Logitech G9/G604/M720/MX518, Microsoft Intellimouse, Trust 16341 BT Mouse
Windows 10 x64, AMD Ryzen 5900x, MSI x570 Tomahawk, 32GB DDR4,
nVidia RTX 2070s, Evo 970 1Tb NVME, 2x2TB WD Black (RAID1)
shodan
New User
Posts: 10
Joined: Tue Feb 13, 2024 5:22 am

Re: How can I perform a simulated key, only when pressing two buttons at the same time ?

Post by shodan »

Hi !

Yes this year is very bad for snow, I live near the border and didn't even have to clear the snow in my driveway. There just wasn't enough !

Terrible skidoo season ! I think they didn't even clear the local snowmobile trails in my region.

I have now installed the latest beta version of xmbc 2.21 beta 33

I made a video with debug mode plus a visible tail on the log file.

I notice that the order that the buttons are releases has an impact on the stuck keys.

My chord only works with mouse 5 first and then the mouse 1/2/3 buttons

So in this video I explored the 4 possibilities

perform alt-drag, release leftbutton THEN mouse 5

perform alt-drag, release mouse 5 THEN leftbutton

perform alt-resize release rightbutton THEN mouse 5

perform alt-resize release mouse 5 THEN rightbutton

Here are the behaviours I have observed

1. sticky next leftbutton

When performing a mouse 5 then leftbutton chord, which is an "alt drag" movement

After releasing the leftbutton then mouse 5

The next leftbutton click will stick

Example selecting text and releasing leftbutton, you can still move the selection around even though all buttons are released.

Same thing with a desktop selection

I demonstrate this in this video

https://youtu.be/kRSvDXytq_U

You can see that this only occurs for the next click.
The click after that is normal as far as I can tell.

2. sticky ALT

This seems to occur when mouse5 is release before the leftbutton

It appears as the ALT remains stuck on.

Even though mouse 5 is no longer being pressed. I can alt+drag and alt+resize many times without issue. On the desktop I can make a selection unhindered(probably because explorer.exe is in the altsnap process blacklist)

All the other processes can be alt+drag and alt+resized without pressing ALT nor mouse5 first.

This situation occurs until mouse5 is pressed and released. This restores normal operation

Here is the video demonstrating this

https://youtu.be/mvj87zIRN88


3. Stuck ALT is more stuck than it seems

In this video, I will again do the mouse5 release first.
And that will cause the alt key to become stuck.

I will unstick the ALT key by pressing mouse5 once.

Then I can select text in the browser.

But I noticed it does not fix everything.

The ALT key is still somehow stuck in other ways.

One thing I try is simple mouse4/5 presses in firefox. This should change to next/previous tabs as demonstrated at the beginning of the video.

However, once of the ALT becomes stuck. Even after releasing ALT by pressing mouse5 and demonstrating it by selecting text. Pressing mouse4/5 alone, no longer changes the tab.

Then I click and drag a desktop icon, and notice it creates a shortcut.
Creating a shortcut in explorer is done by alt dragging a file or folder. Indicating that ALT is still stuck for explorer.exe.

https://youtu.be/fC_tG-MmLV8

I found that to fully release you have to do as follows while the key is stuck

press and release mouse 5

then press mouse 5 press leftbutton release leftbutton release mouse 5

And then the next leftbutton might be a stuck as per #1

Here is doing this procedure 3 times

https: youtu.be/GHmHbqVKm38

https: youtu.be/XEA3EjmDle0

https: youtu.be/Vo1C8eF7B3E

I could not manage to capture a stuck next click. But I'm sure it did once at least !

This is as much as I could figure out for now !

NOTE : While writing this message, when I pressed submit, it asked me to login again, I did and my whole message was gone !
However, I had anticipated that and I copied the whole message in my clipboard. Still that would have been very discouraging !

That is all for now, thanks !
User avatar
phil
Site Admin
Posts: 7670
Joined: Sun Apr 06, 2003 11:12 pm

Re: How can I perform a simulated key, only when pressing two buttons at the same time ?

Post by phil »

Yes it was really bad for snow - we managed to find some north of Mont Laurier, and while we had to cancel/change plans while we were there, we managed to do what we went to do :). All good - but next time we will need to be more careful, and perhaps not book too far in advance lol.

Anyway, I will need to study your message and logs in detail - I can't do that tonight (its too late here now) but I will try and get to it sometime this week (although its a bit busy with Easter and all that - I'll be away all Easter weekend)
--[ Phil ]--
--[ Administrator & XMBC Author ]--
Logitech G9/G604/M720/MX518, Microsoft Intellimouse, Trust 16341 BT Mouse
Windows 10 x64, AMD Ryzen 5900x, MSI x570 Tomahawk, 32GB DDR4,
nVidia RTX 2070s, Evo 970 1Tb NVME, 2x2TB WD Black (RAID1)
Post Reply