Beispiel #1
0
func (osx *osxSystemObject) GetActiveDevices() map[gin.DeviceType][]gin.DeviceIndex {
	globalLock.Lock()
	defer globalLock.Unlock()
	var first_device_id *C.DeviceId
	fdip := (*unsafe.Pointer)(unsafe.Pointer(&first_device_id))
	var length C.int
	C.GetActiveDevices(fdip, &length)
	c_ids := (*[1000]C.DeviceId)(unsafe.Pointer(first_device_id))[:length]
	ret := make(map[gin.DeviceType][]gin.DeviceIndex, length)
	for _, c_id := range c_ids {
		dt := gin.DeviceType(c_id.Type)
		di := gin.DeviceIndex(c_id.Index)
		ret[dt] = append(ret[dt], di)
	}
	return ret
}
Beispiel #2
0
// TODO: Make sure that events are given in sorted order (by timestamp)
// TODO: Adjust timestamp on events so that the oldest timestamp is newer than the
//       newest timestemp from the events from the previous call to GetInputEvents
//       Actually that should be in system
func (linux *linuxSystemObject) GetInputEvents() ([]gin.OsEvent, int64) {
	var first_event *C.GlopKeyEvent
	cp := (*unsafe.Pointer)(unsafe.Pointer(&first_event))
	var length C.int
	var horizon C.longlong
	C.GlopGetInputEvents(cp, unsafe.Pointer(&length), unsafe.Pointer(&horizon))
	linux.horizon = int64(horizon)
	c_events := (*[1000]C.GlopKeyEvent)(unsafe.Pointer(first_event))[:length]
	events := make([]gin.OsEvent, length)
	for i := range c_events {
		events[i] = gin.OsEvent{
			KeyId: gin.KeyId{
				Device: gin.DeviceId{
					Index: 5,
					Type:  gin.DeviceTypeKeyboard,
				},
				Index: gin.KeyIndex(c_events[i].index),
			},
			Press_amt: float64(c_events[i].press_amt),
			Timestamp: int64(c_events[i].timestamp),
		}
	}
	done := false
	for !done {
		select {
		case event := <-jsCollect:
			events = append(events, gin.OsEvent{
				KeyId: gin.KeyId{
					Device: gin.DeviceId{
						Index: gin.DeviceIndex(event.Index + 1),
						Type:  gin.DeviceTypeController,
					},
					Index: gin.KeyIndex(event.Key),
				},
				Press_amt: event.FValue,
				Timestamp: int64(event.TimestampMs),
			})
		default:
			done = true
		}
	}
	sort.Sort(osEventSlice(events))
	return events, linux.horizon
	// return nil, 0
}
Beispiel #3
0
// TODO: Make sure that events are given in sorted order (by timestamp)
// TODO: Adjust timestamp on events so that the oldest timestamp is newer than the
//       newest timestemp from the events from the previous call to GetInputEvents
//       Actually that should be in system
func (osx *osxSystemObject) GetInputEvents() ([]gin.OsEvent, int64) {
	var first_event *C.KeyEvent
	cp := (*unsafe.Pointer)(unsafe.Pointer(&first_event))
	var length C.int
	var horizon C.longlong

	globalLock.Lock()
	C.GetInputEvents(cp, &length, &horizon)
	globalLock.Unlock()

	osx.horizon = int64(horizon)
	c_events := (*[1000]C.KeyEvent)(unsafe.Pointer(first_event))[:length]
	events := make([]gin.OsEvent, length)
	for i := range c_events {
		var device_type gin.DeviceType
		switch c_events[i].device_type {
		case C.deviceTypeKeyboard:
			device_type = gin.DeviceTypeKeyboard
		case C.deviceTypeMouse:
			device_type = gin.DeviceTypeMouse
		case C.deviceTypeController:
			device_type = gin.DeviceTypeController
		default:
			panic("Unknown device type")
		}
		events[i] = gin.OsEvent{
			KeyId: gin.KeyId{
				Device: gin.DeviceId{
					Index: gin.DeviceIndex(c_events[i].device_index),
					Type:  device_type,
				},
				Index: gin.KeyIndex(c_events[i].key_index),
			},
			Press_amt: float64(c_events[i].press_amt),
			Timestamp: int64(c_events[i].timestamp) / 1000000,
		}
	}
	return events, osx.horizon
}