Skip to content

Commit

Permalink
Compensate hand position shift during mouse freeze/unfreeze
Browse files Browse the repository at this point in the history
  • Loading branch information
Timo Aho committed Nov 6, 2015
1 parent 515f895 commit 74ba668
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 17 deletions.
2 changes: 1 addition & 1 deletion client/etc/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ recipes:
mouseButton2:
signs:
- 'pinchRing'
action: 'mouse2Click'
action: 'toggleFreeze'
# compoundRecipe:
# signs:
# - 'pinchRing'
Expand Down
70 changes: 54 additions & 16 deletions client/src/ActionController.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,17 @@ class ActionController
@robot = require 'robotjs'
@mouseState = 'free' # free|frozen
@position =
x: undefined
y: undefined
x: 0
y: 0
@freezePosition =
x: 0
y: 0
@unfreezePosition =
x: 0
y: 0
@offsetMapping =
x: 0
y: 0
@keyboardModel =
test: false
@recipeState = {}
Expand All @@ -28,23 +37,45 @@ class ActionController
if(recipe.tearDownDelay)
@recipeState[name].tearDownDelay = recipe.tearDownDelay

freezeMouse: => @mouseState = 'frozen'
unfreezeMouse: => @mouseState = 'free'
toggleMouseFreeze: =>
freezeMouse: (handPosition) =>
# screenSize = @robot.getScreenSize()
# normalizedHandPosition =
# x: handPosition.x * screenSize.width
# y: handPosition.y * screenSize.height
# @freezePosition = normalizedHandPosition
@freezePosition = @robot.getMousePos()
console.log "Freeze mouse", @freezePosition
@mouseState = 'frozen'

unfreezeMouse: (handPosition) =>
screenSize = @robot.getScreenSize()
normalizedHandPosition =
x: handPosition.x * screenSize.width
y: handPosition.y * screenSize.height
@unfreezePosition = normalizedHandPosition
console.log "Unfreeze mouse", @unfreezePosition
@mouseState = 'free'

toggleMouseFreeze: (handPosition) =>
if (@mouseState == 'frozen')
@mouseState = 'free'
@unfreezeMouse handPosition
else if(@mouseState == 'free')
@mouseState = 'frozen'
@freezeMouse handPosition

mouseMove: (position) =>
mouseMove: (handPosition) =>
if(@mouseState == 'free')
@offsetMapping =
x: @freezePosition.x - @unfreezePosition.x
y: @freezePosition.y - @unfreezePosition.y

screenSize = @robot.getScreenSize()
normalizedHandPosition =
x: handPosition.x * screenSize.width
y: handPosition.y * screenSize.height
moveTo =
x: position.x * screenSize.width
y: position.y * screenSize.height
x: normalizedHandPosition.x + @offsetMapping.x
y: normalizedHandPosition.y + @offsetMapping.y
@robot.moveMouse(moveTo.x, moveTo.y)
else
console.log "Mouse is frozen.."

# buttonAction: up|down|click|doubleClick, button: left|right
mouseButton: (buttonAction, button) =>
Expand Down Expand Up @@ -85,19 +116,26 @@ class ActionController
executeAction: (action) =>
#console.log "Execute action: ", action
cmd = @actions[action]
#console.log "cmd: ", cmd
# console.log "cmd: ", cmd
# console.log "Position: ", @position
# console.log "Offset: ", @offsetMapping
screenSize = @robot.getScreenSize()
@debug =
x: @offsetMapping.x * screenSize.width
y: @offsetMapping.y * screenSize.height
#console.log "Debug: ", @debug

if(cmd.feedback?)
if(cmd.feedback.audio?)
window.feedback.audioNotification cmd.feedback.audio

if(cmd.type == 'mouse')
if(cmd.action == 'freeze')
@freezeMouse()
@freezeMouse(@position)
if(cmd.action == 'unfreeze')
@unfreezeMouse()
@unfreezeMouse(@position)
if(cmd.action == 'toggleFreeze')
@toggleMouseFreeze()
@toggleMouseFreeze(@position)
if(cmd.action in ['up', 'down', 'click', 'doubleClick'])
@mouseButton cmd.action, cmd.target
if(cmd.action == 'move')
Expand Down

0 comments on commit 74ba668

Please sign in to comment.