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 {
|
||||
message
|
||||
ID uint64
|
||||
Value string
|
||||
Mask int64
|
||||
ID uint64
|
||||
Value string
|
||||
HesitationTime int64
|
||||
Mask int64
|
||||
}
|
||||
|
||||
func (msg *SetInputValue) Encode() []byte {
|
||||
buf := make([]byte, 31+len(msg.Value))
|
||||
buf := make([]byte, 41+len(msg.Value))
|
||||
buf[0] = 18
|
||||
p := 1
|
||||
p = WriteUint(msg.ID, buf, p)
|
||||
p = WriteString(msg.Value, buf, p)
|
||||
p = WriteInt(msg.HesitationTime, buf, p)
|
||||
p = WriteInt(msg.Mask, buf, p)
|
||||
return buf[:p]
|
||||
}
|
||||
|
|
|
|||
|
|
@ -270,6 +270,9 @@ func DecodeSetInputValue(reader BytesReader) (Message, error) {
|
|||
if msg.Value, err = reader.ReadString(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if msg.HesitationTime, err = reader.ReadInt(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if msg.Mask, err = reader.ReadInt(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
|
|||
|
|
@ -163,9 +163,10 @@ class SetInputTarget(Message):
|
|||
class SetInputValue(Message):
|
||||
__id__ = 18
|
||||
|
||||
def __init__(self, id, value, mask):
|
||||
def __init__(self, id, value, hesitation_time, mask):
|
||||
self.id = id
|
||||
self.value = value
|
||||
self.hesitation_time = hesitation_time
|
||||
self.mask = mask
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -200,6 +200,7 @@ class MessageCodec(Codec):
|
|||
return SetInputValue(
|
||||
id=self.read_uint(reader),
|
||||
value=self.read_string(reader),
|
||||
hesitation_time=self.read_int(reader),
|
||||
mask=self.read_int(reader)
|
||||
)
|
||||
|
||||
|
|
|
|||
|
|
@ -172,11 +172,13 @@ export default class RawMessageReader extends PrimitiveReader {
|
|||
case 18: {
|
||||
const id = this.readUint(); if (id === 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() }
|
||||
return {
|
||||
tp: MType.SetInputValue,
|
||||
id,
|
||||
value,
|
||||
hesitationTime,
|
||||
mask,
|
||||
};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -156,6 +156,7 @@ export interface RawSetInputValue {
|
|||
tp: MType.SetInputValue,
|
||||
id: number,
|
||||
value: string,
|
||||
hesitationTime: number,
|
||||
mask: number,
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -98,6 +98,7 @@ type TrSetInputValue = [
|
|||
type: 18,
|
||||
id: number,
|
||||
value: string,
|
||||
hesitationTime: number,
|
||||
mask: number,
|
||||
]
|
||||
|
||||
|
|
@ -549,7 +550,8 @@ export default function translate(tMsg: TrackerMessage): RawMessage | null {
|
|||
tp: MType.SetInputValue,
|
||||
id: tMsg[1],
|
||||
value: tMsg[2],
|
||||
mask: tMsg[3],
|
||||
hesitationTime: tMsg[3],
|
||||
mask: tMsg[4],
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -94,6 +94,7 @@ end
|
|||
message 18, 'SetInputValue' do
|
||||
uint 'ID'
|
||||
string 'Value'
|
||||
int 'HesitationTime'
|
||||
int 'Mask'
|
||||
end
|
||||
message 19, 'SetInputChecked' do
|
||||
|
|
|
|||
|
|
@ -159,6 +159,7 @@ export type SetInputValue = [
|
|||
/*type:*/ Type.SetInputValue,
|
||||
/*id:*/ number,
|
||||
/*value:*/ string,
|
||||
/*hesitationTime:*/ number,
|
||||
/*mask:*/ number,
|
||||
]
|
||||
|
||||
|
|
|
|||
|
|
@ -172,12 +172,14 @@ export function SetInputTarget(
|
|||
export function SetInputValue(
|
||||
id: number,
|
||||
value: string,
|
||||
hesitationTime: number,
|
||||
mask: number,
|
||||
): Messages.SetInputValue {
|
||||
return [
|
||||
Messages.Type.SetInputValue,
|
||||
id,
|
||||
value,
|
||||
hesitationTime,
|
||||
mask,
|
||||
]
|
||||
}
|
||||
|
|
|
|||
|
|
@ -129,9 +129,10 @@ export default function (app: App, opts: Partial<Options>): void {
|
|||
value = ''
|
||||
break
|
||||
}
|
||||
// @ts-ignore if hesitationTime > 150 add it ???
|
||||
console.log(node.or_inputHesitation)
|
||||
app.send(SetInputValue(id, value, mask))
|
||||
|
||||
// @ts-ignore maybe if hesitationTime > 150 ?
|
||||
const hesitationTime = node.or_inputHesitation || 0
|
||||
app.send(SetInputValue(id, value, hesitationTime, mask))
|
||||
}
|
||||
|
||||
const inputValues: Map<number, string> = new Map()
|
||||
|
|
|
|||
|
|
@ -107,12 +107,45 @@ export default function (app: App): void {
|
|||
let mouseTargetTime = 0
|
||||
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(() => {
|
||||
mousePositionX = -1
|
||||
mousePositionY = -1
|
||||
mousePositionChanged = false
|
||||
mouseTarget = null
|
||||
selectorMap = {}
|
||||
if (checkIntervalId) {
|
||||
clearInterval(checkIntervalId)
|
||||
}
|
||||
})
|
||||
|
||||
const sendMouseMove = (): void => {
|
||||
|
|
@ -146,6 +179,14 @@ export default function (app: App): void {
|
|||
mousePositionX = e.clientX + left
|
||||
mousePositionY = e.clientY + top
|
||||
mousePositionChanged = true
|
||||
|
||||
const nextDirection = Math.sign(e.movementX)
|
||||
distance += Math.abs(e.movementX) + Math.abs(e.movementY)
|
||||
|
||||
if (nextDirection !== direction) {
|
||||
direction = nextDirection
|
||||
directionChangeCount++
|
||||
}
|
||||
},
|
||||
false,
|
||||
)
|
||||
|
|
|
|||
|
|
@ -67,7 +67,7 @@ export default class MessageEncoder extends PrimitiveEncoder {
|
|||
break
|
||||
|
||||
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
|
||||
|
||||
case Messages.Type.SetInputChecked:
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue