Home | Blog | Software | Reviews and Features | Forum | Help | Donate | About us
topbanner_forum
  *

avatar image

Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
  • December 10, 2016, 03:00:31 AM
  • Proudly celebrating 10 years online.
  • Donate now to become a lifetime supporting member of the site and get a non-expiring license key for all of our programs.
  • donate

Author Topic: change mouse behaviour  (Read 1191 times)

kalos

  • Member
  • Joined in 2006
  • **
  • default avatar
  • Posts: 1,477
    • View Profile
    • Donate to Member
change mouse behaviour
« on: January 27, 2015, 04:10:03 PM »
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

  • Honorary Member
  • Joined in 2009
  • **
  • Posts: 571
  • The Gent with the White Hat
    • View Profile
    • Donate to Member
Re: change mouse behaviour
« Reply #1 on: January 27, 2015, 04:27:53 PM »
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

  • Global Moderator
  • Joined in 2005
  • *****
  • Posts: 4,669
    • View Profile
    • Donate to Member
Re: change mouse behaviour
« Reply #2 on: January 27, 2015, 04:32:41 PM »
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?

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.
« Last Edit: January 27, 2015, 08:23:56 PM by skwire, Reason: Grammatical error. »

kalos

  • Member
  • Joined in 2006
  • **
  • default avatar
  • Posts: 1,477
    • View Profile
    • Donate to Member
Re: change mouse behaviour
« Reply #3 on: January 29, 2015, 01:18:56 PM »
so, it's not a simple way to do it?

MilesAhead

  • Supporting Member
  • Joined in 2009
  • **
  • Posts: 7,290
    • View Profile
    • Miles Ahead Software
    • Donate to Member
Re: change mouse behaviour
« Reply #4 on: January 29, 2015, 01:54:24 PM »
so, it's not a simple way to do it?

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


kalos

  • Member
  • Joined in 2006
  • **
  • default avatar
  • Posts: 1,477
    • View Profile
    • Donate to Member
Re: change mouse behaviour
« Reply #5 on: January 29, 2015, 02:25:22 PM »
that script is good, but there is a problem:

I have set firefox, when I right click on a link, to open the link in a background tab

so maybe you can adjust the script NOT to work when the cursor is a "hand" or IBeam, and when I focus on a link (not sure if AHK can detect this) (you know that when a cursor hovers over a link, it becomes underlined)?

also, can you enrich it, so that it when the cursor is IBeam, and perhaps there is some text selected (not sure if AHK can detect this), to copy the text? send ctrl+c?

last, the script works when I right click ANYWHERE on the screen, even outside the firefox window, while it should work ONLY on the webpage area, not in the Windows taskbar or the area of the tabs, etc
« Last Edit: January 29, 2015, 02:30:25 PM by kalos »

MilesAhead

  • Supporting Member
  • Joined in 2009
  • **
  • Posts: 7,290
    • View Profile
    • Miles Ahead Software
    • Donate to Member
Re: change mouse behaviour
« Reply #6 on: January 29, 2015, 04:56:17 PM »
Quote


last, the script works when I right click ANYWHERE on the screen, even outside the firefox window, while it should work ONLY on the webpage area, not in the Windows taskbar or the area of the tabs, etc

That's what I mentioned about Firefox having the focus until you click something else.  When you program an extension you have access to internal variables, document objects etc..  I've never done an extension.  As skwire mentioned you would have to do one for each browser.  That's why most extension writers write for one browser.  There's just too many finicky details.  Some things you can do from the outside.  You can send control c to copy selected text to the clipboard.  But if the text is a link label without the link info itself you just get the text, not the link.  There's so many exceptions that the user would be frustrated that it does not work so often.

Many programmers do IE because they can program it using the ActiveX COM interface rather than just sending clicks etc..  Have you looked at the shortcut list for Firefox? I don't know if they can be reassigned like many editors can.

I have a file Transpose.ahk where I stick odds and ends for some browsers and editors.  Some things can be done such as looking up the word left of the caret when in an editbox on a forum etc..  I'll post it so you can look it over to get an idea.  It's a hodgepodge though.  It's for my own use so please ignore references to defunct domains etc..