change(tracker): add mouse shake and update input hesitation message
This commit is contained in:
parent
969b192146
commit
018f618e12
13 changed files with 68 additions and 10 deletions
|
|
@ -531,17 +531,19 @@ func (msg *SetInputTarget) TypeID() int {
|
||||||
|
|
||||||
type SetInputValue struct {
|
type SetInputValue struct {
|
||||||
message
|
message
|
||||||
ID uint64
|
ID uint64
|
||||||
Value string
|
Value string
|
||||||
Mask int64
|
HesitationTime int64
|
||||||
|
Mask int64
|
||||||
}
|
}
|
||||||
|
|
||||||
func (msg *SetInputValue) Encode() []byte {
|
func (msg *SetInputValue) Encode() []byte {
|
||||||
buf := make([]byte, 31+len(msg.Value))
|
buf := make([]byte, 41+len(msg.Value))
|
||||||
buf[0] = 18
|
buf[0] = 18
|
||||||
p := 1
|
p := 1
|
||||||
p = WriteUint(msg.ID, buf, p)
|
p = WriteUint(msg.ID, buf, p)
|
||||||
p = WriteString(msg.Value, buf, p)
|
p = WriteString(msg.Value, buf, p)
|
||||||
|
p = WriteInt(msg.HesitationTime, buf, p)
|
||||||
p = WriteInt(msg.Mask, buf, p)
|
p = WriteInt(msg.Mask, buf, p)
|
||||||
return buf[:p]
|
return buf[:p]
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -270,6 +270,9 @@ func DecodeSetInputValue(reader BytesReader) (Message, error) {
|
||||||
if msg.Value, err = reader.ReadString(); err != nil {
|
if msg.Value, err = reader.ReadString(); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
if msg.HesitationTime, err = reader.ReadInt(); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
if msg.Mask, err = reader.ReadInt(); err != nil {
|
if msg.Mask, err = reader.ReadInt(); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -163,9 +163,10 @@ class SetInputTarget(Message):
|
||||||
class SetInputValue(Message):
|
class SetInputValue(Message):
|
||||||
__id__ = 18
|
__id__ = 18
|
||||||
|
|
||||||
def __init__(self, id, value, mask):
|
def __init__(self, id, value, hesitation_time, mask):
|
||||||
self.id = id
|
self.id = id
|
||||||
self.value = value
|
self.value = value
|
||||||
|
self.hesitation_time = hesitation_time
|
||||||
self.mask = mask
|
self.mask = mask
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -200,6 +200,7 @@ class MessageCodec(Codec):
|
||||||
return SetInputValue(
|
return SetInputValue(
|
||||||
id=self.read_uint(reader),
|
id=self.read_uint(reader),
|
||||||
value=self.read_string(reader),
|
value=self.read_string(reader),
|
||||||
|
hesitation_time=self.read_int(reader),
|
||||||
mask=self.read_int(reader)
|
mask=self.read_int(reader)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -172,11 +172,13 @@ export default class RawMessageReader extends PrimitiveReader {
|
||||||
case 18: {
|
case 18: {
|
||||||
const id = this.readUint(); if (id === null) { return resetPointer() }
|
const id = this.readUint(); if (id === null) { return resetPointer() }
|
||||||
const value = this.readString(); if (value === null) { return resetPointer() }
|
const value = this.readString(); if (value === null) { return resetPointer() }
|
||||||
|
const hesitationTime = this.readInt(); if (hesitationTime === null) { return resetPointer() }
|
||||||
const mask = this.readInt(); if (mask === null) { return resetPointer() }
|
const mask = this.readInt(); if (mask === null) { return resetPointer() }
|
||||||
return {
|
return {
|
||||||
tp: MType.SetInputValue,
|
tp: MType.SetInputValue,
|
||||||
id,
|
id,
|
||||||
value,
|
value,
|
||||||
|
hesitationTime,
|
||||||
mask,
|
mask,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -156,6 +156,7 @@ export interface RawSetInputValue {
|
||||||
tp: MType.SetInputValue,
|
tp: MType.SetInputValue,
|
||||||
id: number,
|
id: number,
|
||||||
value: string,
|
value: string,
|
||||||
|
hesitationTime: number,
|
||||||
mask: number,
|
mask: number,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -98,6 +98,7 @@ type TrSetInputValue = [
|
||||||
type: 18,
|
type: 18,
|
||||||
id: number,
|
id: number,
|
||||||
value: string,
|
value: string,
|
||||||
|
hesitationTime: number,
|
||||||
mask: number,
|
mask: number,
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
@ -549,7 +550,8 @@ export default function translate(tMsg: TrackerMessage): RawMessage | null {
|
||||||
tp: MType.SetInputValue,
|
tp: MType.SetInputValue,
|
||||||
id: tMsg[1],
|
id: tMsg[1],
|
||||||
value: tMsg[2],
|
value: tMsg[2],
|
||||||
mask: tMsg[3],
|
hesitationTime: tMsg[3],
|
||||||
|
mask: tMsg[4],
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -94,6 +94,7 @@ end
|
||||||
message 18, 'SetInputValue' do
|
message 18, 'SetInputValue' do
|
||||||
uint 'ID'
|
uint 'ID'
|
||||||
string 'Value'
|
string 'Value'
|
||||||
|
int 'HesitationTime'
|
||||||
int 'Mask'
|
int 'Mask'
|
||||||
end
|
end
|
||||||
message 19, 'SetInputChecked' do
|
message 19, 'SetInputChecked' do
|
||||||
|
|
|
||||||
|
|
@ -159,6 +159,7 @@ export type SetInputValue = [
|
||||||
/*type:*/ Type.SetInputValue,
|
/*type:*/ Type.SetInputValue,
|
||||||
/*id:*/ number,
|
/*id:*/ number,
|
||||||
/*value:*/ string,
|
/*value:*/ string,
|
||||||
|
/*hesitationTime:*/ number,
|
||||||
/*mask:*/ number,
|
/*mask:*/ number,
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -172,12 +172,14 @@ export function SetInputTarget(
|
||||||
export function SetInputValue(
|
export function SetInputValue(
|
||||||
id: number,
|
id: number,
|
||||||
value: string,
|
value: string,
|
||||||
|
hesitationTime: number,
|
||||||
mask: number,
|
mask: number,
|
||||||
): Messages.SetInputValue {
|
): Messages.SetInputValue {
|
||||||
return [
|
return [
|
||||||
Messages.Type.SetInputValue,
|
Messages.Type.SetInputValue,
|
||||||
id,
|
id,
|
||||||
value,
|
value,
|
||||||
|
hesitationTime,
|
||||||
mask,
|
mask,
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -129,9 +129,10 @@ export default function (app: App, opts: Partial<Options>): void {
|
||||||
value = ''
|
value = ''
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
// @ts-ignore if hesitationTime > 150 add it ???
|
|
||||||
console.log(node.or_inputHesitation)
|
// @ts-ignore maybe if hesitationTime > 150 ?
|
||||||
app.send(SetInputValue(id, value, mask))
|
const hesitationTime = node.or_inputHesitation || 0
|
||||||
|
app.send(SetInputValue(id, value, hesitationTime, mask))
|
||||||
}
|
}
|
||||||
|
|
||||||
const inputValues: Map<number, string> = new Map()
|
const inputValues: Map<number, string> = new Map()
|
||||||
|
|
|
||||||
|
|
@ -107,12 +107,45 @@ export default function (app: App): void {
|
||||||
let mouseTargetTime = 0
|
let mouseTargetTime = 0
|
||||||
let selectorMap: { [id: number]: string } = {}
|
let selectorMap: { [id: number]: string } = {}
|
||||||
|
|
||||||
|
let velocity = 0
|
||||||
|
let direction = 0
|
||||||
|
let directionChangeCount = 0
|
||||||
|
let distance = 0
|
||||||
|
let checkIntervalId: NodeJS.Timer
|
||||||
|
const shakeThreshold = 0.005
|
||||||
|
const shakeCheckInterval = 225
|
||||||
|
|
||||||
|
function checkMouseShaking() {
|
||||||
|
const nextVelocity = distance / shakeCheckInterval
|
||||||
|
|
||||||
|
if (!velocity) {
|
||||||
|
velocity = nextVelocity
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
const acceleration = (nextVelocity - velocity) / shakeCheckInterval
|
||||||
|
if (directionChangeCount && acceleration > shakeThreshold) {
|
||||||
|
console.log('Mouse shake detected!')
|
||||||
|
}
|
||||||
|
|
||||||
|
distance = 0
|
||||||
|
directionChangeCount = 0
|
||||||
|
velocity = nextVelocity
|
||||||
|
}
|
||||||
|
|
||||||
|
app.attachStartCallback(() => {
|
||||||
|
checkIntervalId = setInterval(() => checkMouseShaking(), shakeCheckInterval)
|
||||||
|
})
|
||||||
|
|
||||||
app.attachStopCallback(() => {
|
app.attachStopCallback(() => {
|
||||||
mousePositionX = -1
|
mousePositionX = -1
|
||||||
mousePositionY = -1
|
mousePositionY = -1
|
||||||
mousePositionChanged = false
|
mousePositionChanged = false
|
||||||
mouseTarget = null
|
mouseTarget = null
|
||||||
selectorMap = {}
|
selectorMap = {}
|
||||||
|
if (checkIntervalId) {
|
||||||
|
clearInterval(checkIntervalId)
|
||||||
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
const sendMouseMove = (): void => {
|
const sendMouseMove = (): void => {
|
||||||
|
|
@ -146,6 +179,14 @@ export default function (app: App): void {
|
||||||
mousePositionX = e.clientX + left
|
mousePositionX = e.clientX + left
|
||||||
mousePositionY = e.clientY + top
|
mousePositionY = e.clientY + top
|
||||||
mousePositionChanged = true
|
mousePositionChanged = true
|
||||||
|
|
||||||
|
const nextDirection = Math.sign(e.movementX)
|
||||||
|
distance += Math.abs(e.movementX) + Math.abs(e.movementY)
|
||||||
|
|
||||||
|
if (nextDirection !== direction) {
|
||||||
|
direction = nextDirection
|
||||||
|
directionChangeCount++
|
||||||
|
}
|
||||||
},
|
},
|
||||||
false,
|
false,
|
||||||
)
|
)
|
||||||
|
|
|
||||||
|
|
@ -67,7 +67,7 @@ export default class MessageEncoder extends PrimitiveEncoder {
|
||||||
break
|
break
|
||||||
|
|
||||||
case Messages.Type.SetInputValue:
|
case Messages.Type.SetInputValue:
|
||||||
return this.uint(msg[1]) && this.string(msg[2]) && this.int(msg[3])
|
return this.uint(msg[1]) && this.string(msg[2]) && this.int(msg[3]) && this.int(msg[4])
|
||||||
break
|
break
|
||||||
|
|
||||||
case Messages.Type.SetInputChecked:
|
case Messages.Type.SetInputChecked:
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue