예제 #1
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
}
예제 #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 (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
}
예제 #3
0
func getKeysFromString(str string) []gin.KeyId {
	parts := strings.Split(str, "+")
	var kids []gin.KeyId
	for _, part := range parts {
		part = osSpecifyKey(part)
		var kid gin.KeyId
		switch {
		case len(part) == 1: // Single character - should be ascii
			kid = gin.In().GetKeyFlat(
				gin.KeyIndex(part[0]),
				gin.DeviceTypeKeyboard,
				gin.DeviceIndexAny).Id()

		// case part == "ctrl":
		// 	kid = gin.AnyControl

		// case part == "shift":
		// 	kid = gin.AnyShift

		// case part == "alt":
		// 	kid = gin.AnyAlt

		// case part == "gui":
		// 	kid = gin.AnyGui

		case part == "space":
			kid = gin.AnySpace

		case part == "rmouse":
			kid = gin.In().GetKeyFlat(
				gin.MouseRButton,
				gin.DeviceTypeMouse,
				gin.DeviceIndexAny).Id()

		case part == "lmouse":
			kid = gin.In().GetKeyFlat(
				gin.MouseLButton,
				gin.DeviceTypeMouse,
				gin.DeviceIndexAny).Id()

		case part == "up":
			kid = gin.AnyUp

		case part == "down":
			kid = gin.AnyDown

		case part == "left":
			kid = gin.AnyLeft

		case part == "right":
			kid = gin.AnyRight

		default:
			key := gin.In().GetKeyByName(part)
			if key == nil {
				Error().Fatalf("Unknown key '%s'", part)
			}
			kid = key.Id()
		}
		kids = append(kids, kid)
	}
	return kids
}