Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

map mouse axis movement to keyboard buttons


  • Please log in to reply
6 replies to this topic
snowdream
  • Members
  • 2 posts
  • Last active: Oct 07 2009 12:26 AM
  • Joined: 07 Oct 2009
Hello:

I recently discovered this nifty software, but I need some help to start a script. I am hoping to create a script to map mouse movements to the direction keys on the keyboard. So if the mouse moves up by a certain extent, then the key {up} is pressed, and so forth. As well, I would like to map the mouse button for other keys such as x,z,c, space, ect. Finally, I hope to be able to turn this on with a key press such as ctrl or when a window is active.

I collected bits of codes that will do part of these things, but I have no clue on where to start to piece them together. Any help would be greatly appreciated!

Thank you!

[Moved from Scripts & Functions forum. ~jaco0646]

VxE
  • Moderators
  • 3622 posts
  • Last active: Dec 24 2015 02:21 AM
  • Joined: 07 Oct 2006
Gui, 93:+ToolWindow

Sensitivity = 7 ; lower = more sensitive

LCtrl:: ; the left control key is the hotkey

Gui, 93:Show, x-1 y-1 w1 h1 +NoActivate, % (Toggle := !Toggle) 

	? "Mouse to Keys On" : "Mouse to Keys Off"

SetTimer, WatchMouse, % Toggle ? 5 : "off"

MouseGetPos, ox, oy

Keywait, %A_ThisHotkey%

return



WatchMouse:

MouseGetPos, nx, ny

If ( Sensitivity < Abs( nx - ox ) )

{

	Send, % "{blind}" ( nx < ox ? "{Left}" : "{Right}" )

	MouseMove, ox, ny+1-2*(ny > oy), 0

}

If ( Sensitivity < Abs( ny - oy ) )

{

	Send, % "{blind}" ( ny < oy ? "{Up}" : "{Down}" )

	MouseMove, nx+1-2*(nx > ox), oy, 0

}

return



#IfWinExist, Mouse to Keys On

	LButton::z

	MButton::x

	RButton::c

	XButton1::space

	XButton2::LAlt

#IfWinExist
:?:

snowdream
  • Members
  • 2 posts
  • Last active: Oct 07 2009 12:26 AM
  • Joined: 07 Oct 2009
Thank you! That is a great framework to work with.

tacman132
  • Members
  • 9 posts
  • Last active: Jun 20 2010 03:59 PM
  • Joined: 07 Feb 2010
The script didn't work VXE
I put it in a new file an ran it and it just sat there. Am I missing something other then copying and pasting the code you had posted?

VxE
  • Moderators
  • 3622 posts
  • Last active: Dec 24 2015 02:21 AM
  • Joined: 07 Oct 2006

The script didn't work VXE
I put it in a new file an ran it and it just sat there. Am I missing something other then copying and pasting the code you had posted?

Did you press the 'ON' button ?

LCtrl:: ; the left control key is the hotkey



tacman132
  • Members
  • 9 posts
  • Last active: Jun 20 2010 03:59 PM
  • Joined: 07 Feb 2010
Thank you very much it works.
Is there a way to make it attacked after much more movement. For instance 30 pixels? Also I am confused why no window pops up because I see you used gui window.

And unrelated but do you know anything about maybe programming hot spots in gui window. Kind of like in those maps on websites where you click on various countries or something.

VxE
  • Moderators
  • 3622 posts
  • Last active: Dec 24 2015 02:21 AM
  • Joined: 07 Oct 2006

Thank you very much it works.
Is there a way to make it attacked after much more movement. For instance 30 pixels? Also I am confused why no window pops up because I see you used gui window.

Take a look at line 2, the variable "Sensitivity" is set to the number of pixels that you need to move the mouse before the script does anything. There is no visible window because is is (usually) off the screen. The gui window is simply there to trigger the #IfWinExist context.

And unrelated but do you know anything about maybe programming hot spots in gui window. Kind of like in those maps on websites where you click on various countries or something.

Making rectangular hotspots that respond to mouseover is fairly simple (I think there are some examples... try searching for "WM_MOUSEMOVE" and "HWND" ).