Jump to content

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

Mapping Mouse movements to arrow keys


  • Please log in to reply
4 replies to this topic
hapyman
  • Members
  • 48 posts
  • Last active: Jan 24 2012 08:13 PM
  • Joined: 21 Oct 2009
Hey everyone,

Here is some background. I downloaded a free app for my BlackBerry that maps the BB keyboard and trackball to the PC keyboard/mouse over bluetooth. The program works fine but I am using AHK to build extra functionality into it. Currently I am struggling with mapping the mouse movements to keyboard arrow movements. I am doing this so that I can use the BB trackball to navigate menu's and XBMC on my HTPC. I am using a simple toggle to switch between the native mouse movements and the arrow keys.

The problem with the script below seems to be the MouseMove at the end. The program (XBMC or Boxee) detects this and it ruins the SendInput of the arrow keys. If I remove the MouseMove at the end then it goes whacky and enters a neverending loop.

Basically I was wondering if there was anyway to completely hide the mouse movements but at the same time map the mouse movements to the arrow keys (up, down, left, right). I've been going through a lot of threads but nothing addressed this problem. One solution that was beyond me seems to be ClipCursor but not sure if it is right for what I am doing.

Here is the simple script:

NoEnv
#SingleInstance force
#Persistent
SetBatchLines -1
Process Priority,,R


BlockInput SendAndMouse            ; user mouse input is ignored during MouseMove
CoordMode Mouse, Screen     ; absolute coordinates
SetMouseDelay -1            ; fastest action
 
MouseGetPos x0, y0          ; get initial mouse pointer location
SetTimer WatchMouse, 1      ; run the subroutine fast (10..16ms)
Return

WatchMouse:
    MouseGetPos x, y         ; get current mouse position
	If (x < (x0-10))
	{
		SendInput {Left}
	}
	Else If (x > (x0+10))
	{
		SendInput {Right}
	}
	Else If (y > (y0+10))
	{
		SendInput {Down}
	}
	Else If (y < (y0-10))
	{
		SendInput {Up}
	}
	MouseMove x0, y0, 0         ; set mouse to original location
	Return

^z::ExitApp


Leef_me
  • Moderators
  • 8337 posts
  • Last active: Yesterday, 10:01 PM
  • Joined: 08 Apr 2009
What about the idea of changing this line within WatchMouse, to the following?

MouseMove x0, y0, 0         ; set mouse to original location
To:
MouseGetPos x0, y0          ; get initial mouse pointer location

It sort of re-zeros the mouse without the last mousemove.

Theoretically the number of moves left & right will 'cancel out', so to speak. :wink:

I am quite concerned about your settimer rate.

hapyman
  • Members
  • 48 posts
  • Last active: Jan 24 2012 08:13 PM
  • Joined: 21 Oct 2009
Unfortunately had tried that before (that is using MouseGetPos instead). The same problem occurs. The program in question detects the mouse movement and it takes the focus off of where the arrows have put it in the menu. So the arrow inputs are detected but any mouse movement ruins the focus of where the arrow keys are. I am guessing this will be have to be done at a higher level. I.e. with the program that detects the blackberry's inputs.

Or it may be possible to do this with autohotkey but the solution is escaping me right now.

Thanks for the suggestion though. Any other thoughts?

Leef_me
  • Moderators
  • 8337 posts
  • Last active: Yesterday, 10:01 PM
  • Joined: 08 Apr 2009

Thanks for the suggestion though. Any other thoughts?

Unfortunately had tried that before (that is using MouseGetPos instead). The same problem occurs. The program in question detects the mouse movement and it takes the focus off of where the arrows have put it in the menu.

One of us is confused, and I think it is you. :wink:

Execution of the command MouseGetPos does _not_ change the location of the mouse.

Let me say it differently, MouseGetPos does not move the mouse.

You original complaint was that:
The problem with the script below seems to be
the program (XBMC or Boxee) detects
the MouseMove at the end. [of the script]
and it ruins the SendInput of the arrow keys.

If I remove the MouseMove at the end [of the script]
then it goes whacky and enters a neverending loop.

I, Leef_me suggest:
To make the problem go away, don't move the mouse,
but make your script think it returned to x0, y0 by reading
the current position and making it the new x0, y0

dcth
  • Members
  • 1 posts
  • Last active: Oct 22 2010 01:04 AM
  • Joined: 22 Oct 2010
Don't know if hapyman or Leef_me got an agreement, but because I also need this 'mouse to arrowkey' script I keep testing until I got this...

- I've use a lot of the 'logic' on the mouse gesture script to get movement direction and absence of movement
- I'm also take the gosub %gesture% stuff to keep logic ahkish
- What I added is the reset to a fixed position that only occurs when the mouse is on the edge of the screen:
--- Not on every loop, like hapyman's script
--- This also allows me to increment the timer period and movement-detector-range, so arrows will press numb and steady

#SingleInstance force
#Persistent
SetBatchLines -1
Process Priority,,R

	BlockInput mouse            
	CoordMode Mouse, Screen     
	SetMouseDelay -1            

	movementStep = 100
	timerWait = 100
	
	SetTimer gesture, %timerWait%
Return

gesture:
	if winactive("ahk_class BOXEE")
	{
		mousegetpos, xpos2, ypos2

		dx:=xpos2-xpos1     
		dy:=ypos1-ypos2     
		if (abs(dy)>=abs(dx))   
	   {
			if (dy>0)
				track=u  ;track is up
			else
				track=d     ;down   
		} else {
			if (dx>0)
				track=r      ;right
			else
				track=l      ;left
		}
		if (abs(dy)<movementStep and abs(dx)<movementStep)
		{
			track=         ;not tracking at all if no significant change in x or y
			
			if (xpos2<movementStep OR xpos2>A_ScreenWidth-movementStep)
				xpos2 := A_ScreenWidth /2
			if (ypos2<movementStep OR ypos2>A_ScreenHeight-movementStep)
				ypos2 := A_ScreenHeight / 2
				
			MouseMove xpos2, ypos2, 0
		}
		xpos1:=xpos2
		ypos1:=ypos2
		if (track<>SubStr(gesture, 0, 1))     ;ignore track if not changing since previous track
		{
			gesture := track
			if islabel(gesture)              ;checks if gesture is labelled
				gosub, %gesture%         ; eg. gosub, gdr
		}
	}
return

u:
	SendInput {Up}
Return

d:
	SendInput {Down}
Return

l:
	SendInput {Left}
Return

r:
	SendInput {Right}
Return

LButton::
	if winactive("ahk_class BOXEE")
	{
		SendInput {Enter}
	} else {
		SendInput {LButton}
	}
Return

RButton::
	if winactive("ahk_class BOXEE")
	{
		SendInput {Esc}
	} else {
		SendInput {RButton}
	}
Return

P.S. Hope this helps another Boxee lovers :wink:
---
digitalcth.com