Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add feature to move mouse by object #9

Open
wants to merge 1 commit into
base: stable
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ addon/doc/en/
*.pyc
*.nvda-addon
.sconsign.dblite
*.exe
84 changes: 84 additions & 0 deletions addon/globalPlugins/goldenCursor.py
Original file line number Diff line number Diff line change
Expand Up @@ -425,6 +425,13 @@ def script_toggleMouseArrows(self, gesture):
self.bindGesture("kb:leftArrow", "moveMouseLeft")
self.bindGesture("kb:downArrow", "moveMouseDown")
self.bindGesture("kb:upArrow", "moveMouseUp")
_dict={
"kb:control+rightArrow": "moveByObjectRight",
"kb:control+leftArrow": "moveByObjectLeft",
"kb:control+downArrow": "moveByObjectDown",
"kb:control+upArrow": "moveByObjectUp"
}
self.bindGestures(_dict)
# Translators: presented when toggling mouse arrows feature.
ui.message(_("Mouse arrows on"))
else:
Expand Down Expand Up @@ -524,6 +531,83 @@ def moveMouse(self, direction):
if config.conf["goldenCursor"]["reportNewMouseCoordinates"]:
ui.message(str(x if direction in (GCMouseRight, GCMouseLeft) else y))

@scriptHandler.script(
# Translators: Input help message for a Golden Cursor command.
description=_("Moves the Mouse pointer right to the adjacent object "),
gesture="kb:nvda+control+windows+rightArrow"
)
def script_moveByObjectRight(self, gesture):
self.moveMouseByObject(GCMouseRight)


@scriptHandler.script(
# Translators: Input help message for a Golden Cursor command.
description=_("Moves the Mouse pointer left to the adjacent object "),
gesture="kb:nvda+control+windows+leftArrow"
)
def script_moveByObjectLeft(self,gesture):
self.moveMouseByObject(GCMouseLeft)

@scriptHandler.script(
# Translators: Input help message for a Golden Cursor command.
description=_("Moves the Mouse pointer down to the adjacent object"),
gesture="kb:nvda+control+windows+downArrow"
)
def script_moveByObjectDown(self,gesture):
self.moveMouseByObject(GCMouseDown)

@scriptHandler.script(
# Translators: Input help message for a Golden Cursor command.
description=_("Moves the Mouse pointer up to the adjacent object"),
gesture="kb:nvda+control+windows+upArrow"
)
def script_moveByObjectUp(self,gesture):
self.moveMouseByObject(GCMouseUp)

def moveMouseByObject(self, direction):
w, h = api.getDesktopObject().location[2:]
x, y = winUser.getCursorPos()
if direction== GCMouseRight:
# The mouse will jump by 5 pixels in this range.
movementRange= range(x, w, 5)
movingIndex= 0 # HORIZONTAL movement
restrictionBackStep= -5
elif direction== GCMouseLeft:
movementRange= range(x, 0, -5)
movingIndex= 0
restrictionBackStep= 5
elif direction== GCMouseDown:
movementRange= range(y, h, 5)
movingIndex= 1 # vertical movement
restrictionBackStep= -5
elif direction== GCMouseUp:
movementRange= range(y, 0, -5)
movingIndex= 1
restrictionBackStep= 5
# Current mouse object
currentObj= self.getMouse()
for pixelValue in movementRange:
point= (pixelValue, y) if movingIndex==0 else (x, pixelValue)
newObj= currentObj.objectFromPoint(*point)
# The first different object we encounter
if newObj != currentObj:
break
else:
# loop ended without breaking
wx.Bell()
newX, newY= point
if self.restriction and self.getAppRestriction.appModule.appName != newObj.appModule.appName:
# change point from tuple to list, so we can mutate it.
point= list(point)
# Move 5 pixels back to stay in restricted application.
point[movingIndex]=point[movingIndex]+restrictionBackStep
wx.Bell()
# Move mouse to the new position.
setMousePosition(*point)
if config.conf["goldenCursor"]["reportNewMouseCoordinates"]:
x,y= point
ui.message(str(x) if movingIndex==0 else str(y))

def getMouse(self):
return api.getDesktopObject().objectFromPoint(*winUser.getCursorPos())

Expand Down
1 change: 1 addition & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ This add-on allows you to move the mouse using a keyboard and save mouse positio
* Windows+NVDA+P: report mouse position.
* Windows+NVDA+M: sswitch mouse arrows on or off.
* Windows+NVDA+arrow keys (or just arrow keys if mouse arrows is on): move mouse.
* Windows+NVDA+control+arrow keys (or just control+arrow keys if mouse arrows is on): move mouse to adjacent object.

Note: these gestures can be reassigned via NVDA's Input Gestures dialog under Golden Cursor category.

Expand Down