Archived
2
0

send keysyms in uint64

This commit is contained in:
Miroslav Šedivý 2020-06-15 18:57:28 +02:00
parent 36937a0776
commit 9a6ca9b5b0
5 changed files with 44 additions and 39 deletions

View File

@ -123,19 +123,19 @@ export abstract class BaseClient extends EventEmitter<BaseEvents> {
break
case 'keydown':
case 'mousedown':
buffer = new ArrayBuffer(5)
buffer = new ArrayBuffer(11)
payload = new DataView(buffer)
payload.setUint8(0, OPCODE.KEY_DOWN)
payload.setUint16(1, 1, true)
payload.setUint16(3, data.key, true)
payload.setUint16(1, 8, true)
payload.setBigUint64(3, BigInt(data.key), true)
break
case 'keyup':
case 'mouseup':
buffer = new ArrayBuffer(5)
buffer = new ArrayBuffer(11)
payload = new DataView(buffer)
payload.setUint8(0, OPCODE.KEY_UP)
payload.setUint16(1, 1, true)
payload.setUint16(3, data.key, true)
payload.setUint16(1, 8, true)
payload.setBigUint64(3, BigInt(data.key), true)
break
default:
this.emit('warn', `unknown data event: ${event}`)

View File

@ -187,7 +187,7 @@ func (manager *RemoteManager) ButtonDown(code int) error {
return xorg.ButtonDown(code)
}
func (manager *RemoteManager) KeyDown(code int) error {
func (manager *RemoteManager) KeyDown(code uint64) error {
return xorg.KeyDown(code)
}
@ -195,7 +195,7 @@ func (manager *RemoteManager) ButtonUp(code int) error {
return xorg.ButtonUp(code)
}
func (manager *RemoteManager) KeyUp(code int) error {
func (manager *RemoteManager) KeyUp(code uint64) error {
return xorg.KeyUp(code)
}

View File

@ -16,9 +16,9 @@ type RemoteManager interface {
Move(x, y int)
Scroll(x, y int)
ButtonDown(code int) error
KeyDown(code int) error
KeyDown(code uint64) error
ButtonUp(code int) error
KeyUp(code int) error
KeyUp(code uint64) error
ReadClipboard() string
WriteClipboard(data string)
ResetKeys()

View File

@ -33,7 +33,7 @@ type PayloadScroll struct {
type PayloadKey struct {
PayloadHeader
Key uint16
Key uint64
}
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 {
err := manager.remote.ButtonDown(int(payload.Key))
if err != nil {
manager.logger.Warn().Err(err).Msg("key down failed")
manager.logger.Warn().Err(err).Msg("button down failed")
return nil
}
manager.logger.Debug().Msgf("button down %d", payload.Key)
} else {
err := manager.remote.KeyDown(int(payload.Key))
err := manager.remote.KeyDown(uint64(payload.Key))
if err != nil {
manager.logger.Warn().Err(err).Msg("key down failed")
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)
} else {
err := manager.remote.KeyUp(int(payload.Key))
err := manager.remote.KeyUp(uint64(payload.Key))
if err != nil {
manager.logger.Warn().Err(err).Msg("keyup failed")
manager.logger.Warn().Err(err).Msg("key up failed")
return nil
}

View File

@ -19,7 +19,8 @@ import (
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{}
func init() {
@ -54,25 +55,25 @@ func ButtonDown(code int) error {
mu.Lock()
defer mu.Unlock()
if _, ok := debounce[code]; ok {
if _, ok := debounce_button[code]; ok {
return fmt.Errorf("debounced button %v", code)
}
debounce[code] = time.Now()
debounce_button[code] = time.Now()
C.XButton(C.uint(code), C.int(1))
return nil
}
func KeyDown(code int) error {
func KeyDown(code uint64) error {
mu.Lock()
defer mu.Unlock()
if _, ok := debounce[code]; ok {
if _, ok := debounce_key[code]; ok {
return fmt.Errorf("debounced key %v", code)
}
debounce[code] = time.Now()
debounce_key[code] = time.Now()
C.XKey(C.ulong(code), C.int(1))
return nil
@ -82,25 +83,25 @@ func ButtonUp(code int) error {
mu.Lock()
defer mu.Unlock()
if _, ok := debounce[code]; !ok {
if _, ok := debounce_button[code]; !ok {
return fmt.Errorf("debounced button %v", code)
}
delete(debounce, code)
delete(debounce_button, code)
C.XButton(C.uint(code), C.int(0))
return nil
}
func KeyUp(code int) error {
func KeyUp(code uint64) error {
mu.Lock()
defer mu.Unlock()
if _, ok := debounce[code]; !ok {
if _, ok := debounce_key[code]; !ok {
return fmt.Errorf("debounced key %v", code)
}
delete(debounce, code)
delete(debounce_key, code)
C.XKey(C.ulong(code), C.int(0))
return nil
@ -127,31 +128,35 @@ func WriteClipboard(data string) {
}
func ResetKeys() {
for code := range debounce {
if code < 8 {
ButtonUp(code)
} else {
KeyUp(code)
}
for code := range debounce_button {
ButtonUp(code)
delete(debounce, code)
delete(debounce_button, code)
}
for code := range debounce_key {
KeyUp(code)
delete(debounce_key, code)
}
}
func CheckKeys(duration time.Duration) {
t := time.Now()
for code, start := range debounce {
for code, start := range debounce_button {
if t.Sub(start) < duration {
continue
}
ButtonUp(code)
if code < 8 {
ButtonUp(code)
} else {
KeyUp(code)
delete(debounce_button, code)
}
for code, start := range debounce_key {
if t.Sub(start) < duration {
continue
}
KeyUp(code)
delete(debounce, code)
delete(debounce_key, code)
}
}