-
-
Notifications
You must be signed in to change notification settings - Fork 48
/
keyboard.go
49 lines (40 loc) · 1.28 KB
/
keyboard.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package vz
/*
#cgo darwin CFLAGS: -mmacosx-version-min=11 -x objective-c -fno-objc-arc
#cgo darwin LDFLAGS: -lobjc -framework Foundation -framework Virtualization
# include "virtualization_11.h"
# include "virtualization_12.h"
*/
import "C"
import (
"github.com/Code-Hex/vz/v3/internal/objc"
)
// KeyboardConfiguration interface for a keyboard configuration.
type KeyboardConfiguration interface {
objc.NSObject
keyboardConfiguration()
}
type baseKeyboardConfiguration struct{}
func (*baseKeyboardConfiguration) keyboardConfiguration() {}
// USBKeyboardConfiguration is a device that defines the configuration for a USB keyboard.
type USBKeyboardConfiguration struct {
*pointer
*baseKeyboardConfiguration
}
var _ KeyboardConfiguration = (*USBKeyboardConfiguration)(nil)
// NewUSBKeyboardConfiguration creates a new USB keyboard configuration.
//
// This is only supported on macOS 12 and newer, error will
// be returned on older versions.
func NewUSBKeyboardConfiguration() (*USBKeyboardConfiguration, error) {
if err := macOSAvailable(12); err != nil {
return nil, err
}
config := &USBKeyboardConfiguration{
pointer: objc.NewPointer(C.newVZUSBKeyboardConfiguration()),
}
objc.SetFinalizer(config, func(self *USBKeyboardConfiguration) {
objc.Release(self)
})
return config, nil
}