ATTENTION: You are viewing a page formatted for mobile devices; to view the full web page, click HERE.

Main Area and Open Discussion > General Software Discussion

change mouse behaviour

(1/2) > >>

kalos:
hello!

I am interested to modify mouse/keyboard behaviour in various programs, for example to close a tab in firefox when I right click on empty space of the webpage (instead of triggering the context menu, which I want to be triggered when I hold CTRL and right click on empty space of the webpage)

AHK doesn't seem able to do this

I had trouble finding a program that will do this, but I was told that such program to work, it needs to "inject code into explorer, and manipulate it using hooks, and/or access internal memory directly".

can you tell me please how to do it exactly?

thanks!

worstje:
While I don't want to be a negative influence and squash your morale, this is a pretty tall order you are asking for here.

Programs are designed to be interacted with by a user. Some parts are not intended to be changed, and the kind of tricks you describe are meant to change such things. But with that comes all the nitty-gritty stuff that takes some hackers who really like that sort of thing to figure out adequately. Code injection used to be rocket science before the great security realization dawned upon the worlds collective consciousness, making a bad thing, and nowadays it has been given more hurdles to make it even more difficult. (Look into AppInit hooks some time; there is a reason these are hated upon nowadays!) The tiniest of mistakes while hooking into another program can make it behave erratically or outright have it crash at random times; there's a lot of pain ahead of you if you really decide to sink your teeth into this subject. I dare say very few people could tell you how to do it, and especially not 'exactly': comparing this sort of exercise to brain surgery would not be too bad of a comparison to make.

A more suitable alternative would likely be to interact with the Windows accessibility APIs. These do not require hooking and can do a good amount of the things you may want it to, as they are intended to allow programs to control Windows more easily for the handicapped who may not be able to press multiple keys together, read actual text and more of those things. Of course, this may not be as successful with something like responding to rightclicks in the empty area of a webpage.

Finally, there's also the option of tackling your needs with different approaches. Develop a plugin for Firefox to do what you want done in that program. It is _far_ simpler to take that route and simply leverage all the existing plugin infrastructure than it would be to reverse-engineer Firefox' behaviour.

I have done code injection and hooking in the past, and it was some very simple stuff, but getting it stable was a nightmare. If you value your sanity, do not go there.

skwire:
I had trouble finding a program that will do this, but I was told that such program to work, it needs to "inject code into explorer, and manipulate it using hooks, and/or access internal memory directly".

can you tell me please how to do it exactly?-kalos (January 27, 2015, 04:10 PM)
--- End quote ---

Externally manipulating a browser, say, with AHK or other macro program, is a notoriously difficult thing to do.  To do the type of manipulation you're asking about, in a browser, you will have to accomplish it via internal methods.  That is, you will almost certainly have to write a plugin/extension/add-on for each browser you want supported.  This would be MUCH easier than your statement of, "inject code into explorer, and manipulate it using hooks, and/or access internal memory directly."  I don't know that we have many browser plugin coders on DC, so you're probably on your own for this one.  I'd start by researching how to write a plugin for whichever browser you use.

If you're just looking to save time closing tabs, I'd suggest you look into using mouse gestures with your browser of choice (this assumes that you're not currently using mouse gestures, of course).  For instance, to close a tab in Firefox, I right-click and make an "L" shape.  Takes half a second and I still can maintain normal right-click functionality.

kalos:
so, it's not a simple way to do it?

MilesAhead:
so, it's not a simple way to do it?
-kalos (January 29, 2015, 01:18 PM)
--- End quote ---

I agree with skwire.  It's touchy business.

This script would work for the two cases you sited.  But what you will find if you mess with it is, once the browser is the active window, the mouse substitution will stay in effect until you left click someplace else.  For example if you try to right click on the ahk tray icon to close it, instead you will send control w, unless you left click the icon first to change the focus from the browser.


--- ---SendMode Input

;only remap these keys if Firefox Browser is active window
#IfWinActive ahk_class MozillaWindowClass
$RButton::^w
$^RButton::Send {RButton}
return
#IfWinActive

Navigation

[0] Message Index

[#] Next page

Go to full version