Skip to content

Commit

Permalink
added mouse control and feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
JeffreyDavidsz committed Apr 26, 2022
1 parent 23ac58c commit 080fa9f
Show file tree
Hide file tree
Showing 4 changed files with 263 additions and 27 deletions.
56 changes: 48 additions & 8 deletions actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,18 +123,18 @@ exports.getActions = (self) => {
label: 'Change mouse position',
options: [
{
type: 'number',
type: 'textwithvariables',
label: 'X-coordinate',
id: 'x',
default: 100,
minSelection: 1,
width: 6
},
{
type: 'number',
type: 'textwithvariables',
label: 'Y-coordinate',
id: 'y',
default: 100,
minSelection: 1,
width: 6
},
],
},
Expand All @@ -157,6 +157,10 @@ exports.getActions = (self) => {
},
],
},
getMousePosition: {
label: 'Get the position of the mouse on screen',
options: [],
},
msg: {
label: 'Send stringmessage',
options: [
Expand Down Expand Up @@ -220,9 +224,7 @@ exports.getActions = (self) => {
},
],
},
}

actions.specialKeyOS = {
specialKeyOS: {
label: 'special key OS dependent',
options: [
{
Expand All @@ -233,6 +235,44 @@ exports.getActions = (self) => {
choices: self.CHOICES_KEYS_SPECIALS,
},
],
}
},
subscribe: {
label: 'Subscribe to data',
options: [
{
type: 'dropdown',
label: 'Subscribe',
id: 'subscribe',
default: 'subscribe',
choices: [{ id: 'subscribe', label: 'Subscribe' },{ id: 'unsubscribe', label: 'Unsubscribe' }],
},
{
type: 'dropdown',
label: 'Object',
id: 'name',
default: 'mousePosition',
choices: [{ id: 'mousePosition', label: 'mouse position' }],
},
{
type: 'number',
label: 'Interval',
id: 'interval',
default: 1000,
}
]
},
custom: {
label: 'Custom action',
options: [
{
type: 'textinput',
label: 'Custom message',
id: 'custom',
default: '{"type":}',
},
]
},
}

return actions
}
90 changes: 72 additions & 18 deletions hotkey.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,34 @@ class instance extends instance_skel {

this.init_TCP()
this.initPresets()
this.initVariables()
}
/**
* Process incoming data
* @param {JSON obj} data
*/
processData(msg) {
console.log('msg', msg)
switch (msg.type) {
case 'version':
this.setVariable('version', msg.data)
break
case 'license':
this.setVariable('license', msg.data)
break
case 'mousePosition':
this.setVariable('mouseX', msg.x)
this.setVariable('mouseY', msg.y)
break
case 'subscribe':
case 'unsubscribe':
case 'getMousePosition':
break

default:
console.log('Wrong type', msg)
break
}
}

// Functions to handle socket events
Expand All @@ -56,13 +84,23 @@ class instance extends instance_skel {
this.retrying = false
})
this.tcp.on('data', (data) => {
console.log('data', data.toString())
let dataArray = data.toString().trim().split('\r\n')
for (const iterator of dataArray) {
const json = ((raw) => {
try {
return JSON.parse(raw)
} catch (objError) {
if (objError instanceof SyntaxError) {
console.error(objError.name)
} else {
console.error(objError.message)
}
}
})(iterator)
this.processData(json)
}
})

// this.tcp.on('end', this.endEventHandler())
// this.tcp.on('timeout', this.timeoutEventHandler())
// this.tcp.on('drain', this.drainEventHandler())
// this.tcp.on('error', this.errorEventHandler())
this.tcp.on('close', () => {
this.log('info', 'Connection closed')
if (!this.retrying) {
Expand Down Expand Up @@ -146,6 +184,16 @@ class instance extends instance_skel {
debug('destroy', this.id)
}

initVariables() {
let variables = [
{ name: 'version', label: 'VICREO Listener version' },
{ name: 'license', label: 'License' },
{ name: 'mouseX', label: 'mouseX' },
{ name: 'mouseY', label: 'mouseY' },
]
this.setVariableDefinitions(variables)
}

initPresets(updates) {
this.setPresetDefinitions(presets.getPresets(this))
}
Expand Down Expand Up @@ -415,6 +463,11 @@ class instance extends instance_skel {
cmd.password = md5(this.config.password)
break

case 'getMousePosition':
cmd.type = 'getMousePosition'
cmd.password = md5(this.config.password)
break

case 'mouseClick':
cmd.type = 'mouseClick'
cmd.button = opt.button
Expand Down Expand Up @@ -465,20 +518,21 @@ class instance extends instance_skel {
if (opt.modifier1 != 'none') cmd.modifiers.push(opt.modifier1)
if (opt.modifier2 != 'none') cmd.modifiers.push(opt.modifier2)
cmd.password = md5(this.config.password)
break

case 'subscribe':
cmd.type = opt.subscribe
cmd.name = opt.name
cmd.interval = opt.interval
cmd.password = md5(this.config.password)
break

// if (opt.modifier1 != 'none' && opt.modifier2 == 'none') {
// cmd = `{ "key":"${opt.virtualKeyCode}", "type":"processOSX","processName":"${
// opt.processSearchString
// }", "modifiers":["${opt.modifier1}"], "password": "${md5(this.config.password)}" }`
// } else if (opt.modifier2 != 'none' && opt.modifier1 != 'none') {
// cmd = `{ "key":"${opt.virtualKeyCode}", "type":"processOSX","processName":"${
// opt.processSearchString
// }", "modifiers":["${opt.modifier1}","${opt.modifier2}"], "password": "${md5(this.config.password)}" }`
// } else {
// cmd = `{ "key":"${opt.virtualKeyCode}", "type":"processOSX","processName":"${
// opt.processSearchString
// }", "modifiers":[], "password": "${md5(this.config.password)}" }`
// }
case 'custom':
try {
cmd = JSON.parse(opt.custom)
} catch (error) {
console.error('error', error)
}
break
}

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "vicreo-hotkey",
"version": "2.0.14",
"version": "3.0.0",
"api_version": "1.0.0",
"keywords": [
"Software",
Expand Down
142 changes: 142 additions & 0 deletions presets.js
Original file line number Diff line number Diff line change
Expand Up @@ -523,5 +523,147 @@ exports.getPresets = function (self) {
],
})

presets.push({
category: 'Mouse',
bank: {
style: 'text',
text: 'Click left',
size: '14',
color: self.rgb(255, 255, 255),
bgcolor: self.rgb(51, 51, 200),
},
actions: [
{
action: 'mouseClick',
options: {
button: 'left',
double: 'false'
},
},
],
})

presets.push({
category: 'Mouse',
bank: {
style: 'text',
text: 'Click right',
size: '14',
color: self.rgb(255, 255, 255),
bgcolor: self.rgb(51, 51, 200),
},
actions: [
{
action: 'mouseClick',
options: {
button: 'right',
double: 'false'
},
},
],
})

presets.push({
category: 'Mouse',
bank: {
style: 'text',
text: 'Set Mouse\\nposition',
size: '14',
color: self.rgb(255, 255, 255),
bgcolor: self.rgb(51, 51, 200),
},
actions: [
{
action: 'mousePosition',
options: {
x: 500,
y: 500
}
},
],
})

presets.push({
category: 'Mouse',
bank: {
style: 'text',
text: 'Get Mouse\\nposition',
size: '14',
color: self.rgb(255, 255, 255),
bgcolor: self.rgb(51, 51, 200),
},
actions: [
{
action: 'getMousePosition',
},
],
})

presets.push({
category: 'Mouse',
bank: {
style: 'textwithvariables',
text: 'Mouse X:\n$(VICREO hotkey:mouseX)',
size: '14',
color: self.rgb(255, 255, 255),
bgcolor: self.rgb(51, 51, 200),
},
actions: [],
})

presets.push({
category: 'Mouse',
bank: {
style: 'textwithvariables',
text: 'Mouse Y:\n$(VICREO hotkey:mouseY)',
size: '14',
color: self.rgb(255, 255, 255),
bgcolor: self.rgb(51, 51, 200),
},
actions: [],
})

presets.push({
category: 'Mouse',
bank: {
style: 'text',
text: 'Subscribe\\nto position',
size: '14',
color: self.rgb(255, 255, 255),
bgcolor: self.rgb(51, 51, 200),
},
actions: [
{
action: 'subscribe',
options: {
subscribe: 'subscribe',
name: 'mousePosition',
interval: 1000
},
},
],
})

presets.push({
category: 'Mouse',
bank: {
style: 'text',
text: 'Unsubscribe\\nto position',
size: '14',
color: self.rgb(255, 255, 255),
bgcolor: self.rgb(51, 51, 200),
},
actions: [
{
action: 'subscribe',
options: {
subscribe: 'unsubscribe',
name: 'mousePosition',
interval: 1000
},
},
],
})

return presets
}

0 comments on commit 080fa9f

Please sign in to comment.