0

I recently got an awesome mouse and found the back & forward buttons nearly useless. However, they were well placed so I decided to try and make a little program.

Is it possible to make a PowerShell/Batch program that will:
1. Deploy an if statement that will be triggered by a keyboard shortcut (ALT + RIGHT & ALT + LEFT)
2. Once the if statement is triggered, reject the keys as if nothing happened (most likely by sending the keys to the script instead of the current program)
3. Send new keys to do the job.

This would be like remapping the forward/back button - without any software, just a home-made solution.

FYI-

This does NOT work:
How to check if a key was pressed in Batch?

Community
  • 1
  • 1
Roke
  • 300
  • 1
  • 6
  • 27
  • 3
    This can't be done for multiple reasons, the two biggest being that batch has no event handlers, and the command line cannot (by design!) acknowledge the existence of a mouse. Also, any mouse worth using that comes with extra buttons will already have software that allows you to remap the buttons. – SomethingDark Nov 18 '15 at 03:44
  • *Please try to use batch- PowerShell it is "dangerous" to allow all powershell programs to run.* Sorry, but what the hell ? Please use dedicated mouse software to accomplish this. – sodawillow Nov 18 '15 at 08:42
  • That's what ppl say. That's why I put it in quotes. Besides, it did not come with software; and the amazon description says 'no programming function' or something like that. – Roke Nov 18 '15 at 12:38
  • maybe [this](http://www.howtogeek.com/howto/14400/use-those-extra-mouse-buttons-to-increase-efficiency/) helps? (a GUI program, not a CLI-solution) – Stephan Nov 18 '15 at 13:50

1 Answers1

0

You can do this with Powershell!.

You'd need to use a global windows hook. Looks like it would be either the WH_KEYBOARD_LL or WH_KEYBOARD hook.

To do that your PS script will need to P/Invoke several Win32 APIs and map Win32 structures to managed structures.

I've never done anything with Windows hooks, but offhand it seems like this would be moderately (if not seriously) complicated. And doing it from PS probably makes it more complicated than it would be from C/C++.

However I have hooked a WndProc from PS where I found it easier to implement the functionality I needed than in C++. In the long run it was worth the initial hurdles because a lot of functionality was implemented in PS. So it all depends on your circumstances.

Χpẘ
  • 3,403
  • 1
  • 13
  • 22
  • This is a good start. Can you tell me how to do this...? I'm really sorry, I have NO experience with PS but with batch, so I don't know what to do here. As you say C++ would make the job easier, I'm totally fine with that. – Roke Nov 19 '15 at 20:48
  • What have you tried? Have you looked for any sample source code? As you may have already read, questions on SO are programmer to programmer. You are expected to show what you've tried and what's not working. – Χpẘ Nov 21 '15 at 02:21