mirror of
https://github.com/m1k1o/neko.git
synced 2024-07-24 14:40:50 +12:00
send keysyms in uint64
This commit is contained in:
parent
36937a0776
commit
9a6ca9b5b0
@ -123,19 +123,19 @@ export abstract class BaseClient extends EventEmitter<BaseEvents> {
|
|||||||
break
|
break
|
||||||
case 'keydown':
|
case 'keydown':
|
||||||
case 'mousedown':
|
case 'mousedown':
|
||||||
buffer = new ArrayBuffer(5)
|
buffer = new ArrayBuffer(11)
|
||||||
payload = new DataView(buffer)
|
payload = new DataView(buffer)
|
||||||
payload.setUint8(0, OPCODE.KEY_DOWN)
|
payload.setUint8(0, OPCODE.KEY_DOWN)
|
||||||
payload.setUint16(1, 1, true)
|
payload.setUint16(1, 8, true)
|
||||||
payload.setUint16(3, data.key, true)
|
payload.setBigUint64(3, BigInt(data.key), true)
|
||||||
break
|
break
|
||||||
case 'keyup':
|
case 'keyup':
|
||||||
case 'mouseup':
|
case 'mouseup':
|
||||||
buffer = new ArrayBuffer(5)
|
buffer = new ArrayBuffer(11)
|
||||||
payload = new DataView(buffer)
|
payload = new DataView(buffer)
|
||||||
payload.setUint8(0, OPCODE.KEY_UP)
|
payload.setUint8(0, OPCODE.KEY_UP)
|
||||||
payload.setUint16(1, 1, true)
|
payload.setUint16(1, 8, true)
|
||||||
payload.setUint16(3, data.key, true)
|
payload.setBigUint64(3, BigInt(data.key), true)
|
||||||
break
|
break
|
||||||
default:
|
default:
|
||||||
this.emit('warn', `unknown data event: ${event}`)
|
this.emit('warn', `unknown data event: ${event}`)
|
||||||
|
@ -187,7 +187,7 @@ func (manager *RemoteManager) ButtonDown(code int) error {
|
|||||||
return xorg.ButtonDown(code)
|
return xorg.ButtonDown(code)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (manager *RemoteManager) KeyDown(code int) error {
|
func (manager *RemoteManager) KeyDown(code uint64) error {
|
||||||
return xorg.KeyDown(code)
|
return xorg.KeyDown(code)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -195,7 +195,7 @@ func (manager *RemoteManager) ButtonUp(code int) error {
|
|||||||
return xorg.ButtonUp(code)
|
return xorg.ButtonUp(code)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (manager *RemoteManager) KeyUp(code int) error {
|
func (manager *RemoteManager) KeyUp(code uint64) error {
|
||||||
return xorg.KeyUp(code)
|
return xorg.KeyUp(code)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -16,9 +16,9 @@ type RemoteManager interface {
|
|||||||
Move(x, y int)
|
Move(x, y int)
|
||||||
Scroll(x, y int)
|
Scroll(x, y int)
|
||||||
ButtonDown(code int) error
|
ButtonDown(code int) error
|
||||||
KeyDown(code int) error
|
KeyDown(code uint64) error
|
||||||
ButtonUp(code int) error
|
ButtonUp(code int) error
|
||||||
KeyUp(code int) error
|
KeyUp(code uint64) error
|
||||||
ReadClipboard() string
|
ReadClipboard() string
|
||||||
WriteClipboard(data string)
|
WriteClipboard(data string)
|
||||||
ResetKeys()
|
ResetKeys()
|
||||||
|
@ -33,7 +33,7 @@ type PayloadScroll struct {
|
|||||||
|
|
||||||
type PayloadKey struct {
|
type PayloadKey struct {
|
||||||
PayloadHeader
|
PayloadHeader
|
||||||
Key uint16
|
Key uint64
|
||||||
}
|
}
|
||||||
|
|
||||||
func (manager *WebRTCManager) handle(id string, msg webrtc.DataChannelMessage) error {
|
func (manager *WebRTCManager) handle(id string, msg webrtc.DataChannelMessage) error {
|
||||||
@ -87,13 +87,13 @@ func (manager *WebRTCManager) handle(id string, msg webrtc.DataChannelMessage) e
|
|||||||
if payload.Key < 8 {
|
if payload.Key < 8 {
|
||||||
err := manager.remote.ButtonDown(int(payload.Key))
|
err := manager.remote.ButtonDown(int(payload.Key))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
manager.logger.Warn().Err(err).Msg("key down failed")
|
manager.logger.Warn().Err(err).Msg("button down failed")
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
manager.logger.Debug().Msgf("button down %d", payload.Key)
|
manager.logger.Debug().Msgf("button down %d", payload.Key)
|
||||||
} else {
|
} else {
|
||||||
err := manager.remote.KeyDown(int(payload.Key))
|
err := manager.remote.KeyDown(uint64(payload.Key))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
manager.logger.Warn().Err(err).Msg("key down failed")
|
manager.logger.Warn().Err(err).Msg("key down failed")
|
||||||
return nil
|
return nil
|
||||||
@ -119,9 +119,9 @@ func (manager *WebRTCManager) handle(id string, msg webrtc.DataChannelMessage) e
|
|||||||
|
|
||||||
manager.logger.Debug().Msgf("button up %d", payload.Key)
|
manager.logger.Debug().Msgf("button up %d", payload.Key)
|
||||||
} else {
|
} else {
|
||||||
err := manager.remote.KeyUp(int(payload.Key))
|
err := manager.remote.KeyUp(uint64(payload.Key))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
manager.logger.Warn().Err(err).Msg("keyup failed")
|
manager.logger.Warn().Err(err).Msg("key up failed")
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -19,7 +19,8 @@ import (
|
|||||||
|
|
||||||
var ScreenConfigurations = make(map[int]types.ScreenConfiguration)
|
var ScreenConfigurations = make(map[int]types.ScreenConfiguration)
|
||||||
|
|
||||||
var debounce = make(map[int]time.Time)
|
var debounce_button = make(map[int]time.Time)
|
||||||
|
var debounce_key = make(map[uint64]time.Time)
|
||||||
var mu = sync.Mutex{}
|
var mu = sync.Mutex{}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
@ -54,25 +55,25 @@ func ButtonDown(code int) error {
|
|||||||
mu.Lock()
|
mu.Lock()
|
||||||
defer mu.Unlock()
|
defer mu.Unlock()
|
||||||
|
|
||||||
if _, ok := debounce[code]; ok {
|
if _, ok := debounce_button[code]; ok {
|
||||||
return fmt.Errorf("debounced button %v", code)
|
return fmt.Errorf("debounced button %v", code)
|
||||||
}
|
}
|
||||||
|
|
||||||
debounce[code] = time.Now()
|
debounce_button[code] = time.Now()
|
||||||
|
|
||||||
C.XButton(C.uint(code), C.int(1))
|
C.XButton(C.uint(code), C.int(1))
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func KeyDown(code int) error {
|
func KeyDown(code uint64) error {
|
||||||
mu.Lock()
|
mu.Lock()
|
||||||
defer mu.Unlock()
|
defer mu.Unlock()
|
||||||
|
|
||||||
if _, ok := debounce[code]; ok {
|
if _, ok := debounce_key[code]; ok {
|
||||||
return fmt.Errorf("debounced key %v", code)
|
return fmt.Errorf("debounced key %v", code)
|
||||||
}
|
}
|
||||||
|
|
||||||
debounce[code] = time.Now()
|
debounce_key[code] = time.Now()
|
||||||
|
|
||||||
C.XKey(C.ulong(code), C.int(1))
|
C.XKey(C.ulong(code), C.int(1))
|
||||||
return nil
|
return nil
|
||||||
@ -82,25 +83,25 @@ func ButtonUp(code int) error {
|
|||||||
mu.Lock()
|
mu.Lock()
|
||||||
defer mu.Unlock()
|
defer mu.Unlock()
|
||||||
|
|
||||||
if _, ok := debounce[code]; !ok {
|
if _, ok := debounce_button[code]; !ok {
|
||||||
return fmt.Errorf("debounced button %v", code)
|
return fmt.Errorf("debounced button %v", code)
|
||||||
}
|
}
|
||||||
|
|
||||||
delete(debounce, code)
|
delete(debounce_button, code)
|
||||||
|
|
||||||
C.XButton(C.uint(code), C.int(0))
|
C.XButton(C.uint(code), C.int(0))
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func KeyUp(code int) error {
|
func KeyUp(code uint64) error {
|
||||||
mu.Lock()
|
mu.Lock()
|
||||||
defer mu.Unlock()
|
defer mu.Unlock()
|
||||||
|
|
||||||
if _, ok := debounce[code]; !ok {
|
if _, ok := debounce_key[code]; !ok {
|
||||||
return fmt.Errorf("debounced key %v", code)
|
return fmt.Errorf("debounced key %v", code)
|
||||||
}
|
}
|
||||||
|
|
||||||
delete(debounce, code)
|
delete(debounce_key, code)
|
||||||
|
|
||||||
C.XKey(C.ulong(code), C.int(0))
|
C.XKey(C.ulong(code), C.int(0))
|
||||||
return nil
|
return nil
|
||||||
@ -127,31 +128,35 @@ func WriteClipboard(data string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func ResetKeys() {
|
func ResetKeys() {
|
||||||
for code := range debounce {
|
for code := range debounce_button {
|
||||||
if code < 8 {
|
ButtonUp(code)
|
||||||
ButtonUp(code)
|
|
||||||
} else {
|
|
||||||
KeyUp(code)
|
|
||||||
}
|
|
||||||
|
|
||||||
delete(debounce, code)
|
delete(debounce_button, code)
|
||||||
|
}
|
||||||
|
for code := range debounce_key {
|
||||||
|
KeyUp(code)
|
||||||
|
|
||||||
|
delete(debounce_key, code)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func CheckKeys(duration time.Duration) {
|
func CheckKeys(duration time.Duration) {
|
||||||
t := time.Now()
|
t := time.Now()
|
||||||
for code, start := range debounce {
|
for code, start := range debounce_button {
|
||||||
if t.Sub(start) < duration {
|
if t.Sub(start) < duration {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
ButtonUp(code)
|
||||||
|
|
||||||
if code < 8 {
|
delete(debounce_button, code)
|
||||||
ButtonUp(code)
|
}
|
||||||
} else {
|
for code, start := range debounce_key {
|
||||||
KeyUp(code)
|
if t.Sub(start) < duration {
|
||||||
|
continue
|
||||||
}
|
}
|
||||||
|
KeyUp(code)
|
||||||
|
|
||||||
delete(debounce, code)
|
delete(debounce_key, code)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user