Archived
2
0

kbd modifiers - server side

This commit is contained in:
m1k1o 2020-06-20 00:57:37 +02:00
parent e01ab240f1
commit 8c8df119ad
2 changed files with 39 additions and 3 deletions

View File

@ -47,8 +47,11 @@ type Clipboard struct {
} }
type Keyboard struct { type Keyboard struct {
Event string `json:"event"` Event string `json:"event"`
Layout string `json:"layout"` Layout *string `json:"layout,omitempty"`
CapsLock *bool `json:"capsLock,omitempty"`
NumLock *bool `json:"numLock,omitempty"`
ScrollLock *bool `json:"scrollLock,omitempty"`
} }
type Control struct { type Control struct {

View File

@ -116,6 +116,11 @@ func (h *MessageHandler) controlClipboard(id string, session types.Session, payl
return nil return nil
} }
// TODO: Refactor
var CapsLock = false
var NumLock = false
var ScrollLock = false
func (h *MessageHandler) controlKeyboard(id string, session types.Session, payload *message.Keyboard) error { func (h *MessageHandler) controlKeyboard(id string, session types.Session, payload *message.Keyboard) error {
// check if session is host // check if session is host
if !h.sessions.IsHost(id) { if !h.sessions.IsHost(id) {
@ -123,6 +128,34 @@ func (h *MessageHandler) controlKeyboard(id string, session types.Session, paylo
return nil return nil
} }
h.remote.SetKeyboard(payload.Layout) // change layout
if payload.Layout != nil {
h.remote.SetKeyboard(*payload.Layout)
}
// set caps lock
if payload.CapsLock != nil && *payload.CapsLock != CapsLock {
h.remote.KeyDown(0xffe5)
h.remote.KeyUp(0xffe5)
CapsLock = *payload.CapsLock
}
// set num lock
if payload.NumLock != nil && *payload.NumLock != NumLock {
h.remote.KeyDown(0xff7f)
h.remote.KeyUp(0xff7f)
NumLock = *payload.NumLock
}
// set scroll lock
if payload.ScrollLock != nil && *payload.ScrollLock != ScrollLock {
h.remote.KeyDown(0xff14)
h.remote.KeyUp(0xff14)
ScrollLock = *payload.ScrollLock
}
return nil return nil
} }