event/modifiers.go

Functions

Functions

func Has

Has returns true if all the specified modifier bits are set.

 

Example:

 

if mods.Has(ModCtrl | ModShift) {

// Both Ctrl and Shift are pressed

}

func (m Modifiers) Has(mod Modifiers) bool {
	return m&mod == mod
}

func HasAny

HasAny returns true if any of the specified modifier bits are set.

 

Example:

 

if mods.HasAny(ModCtrl | ModSuper) {

// Either Ctrl or Super is pressed

}

func (m Modifiers) HasAny(mod Modifiers) bool {
	return m&mod != 0
}

func IsAlt

IsAlt returns true if the Alt modifier is set.

func (m Modifiers) IsAlt() bool {
	return m.Has(ModAlt)
}

func IsCapsLock

IsCapsLock returns true if Caps Lock is active.

func (m Modifiers) IsCapsLock() bool {
	return m.Has(ModCapsLock)
}

func IsCtrl

IsCtrl returns true if the Control modifier is set.

func (m Modifiers) IsCtrl() bool {
	return m.Has(ModCtrl)
}

func IsNumLock

IsNumLock returns true if Num Lock is active.

func (m Modifiers) IsNumLock() bool {
	return m.Has(ModNumLock)
}

func IsShift

IsShift returns true if the Shift modifier is set.

func (m Modifiers) IsShift() bool {
	return m.Has(ModShift)
}

func IsSuper

IsSuper returns true if the Super modifier is set.

func (m Modifiers) IsSuper() bool {
	return m.Has(ModSuper)
}

func String

func (m Modifiers) String() string {
	if m == ModNone {
		return modNoneStr
	}

	var parts []string
	if m.Has(ModCtrl) {
		parts = append(parts, "Ctrl")
	}
	if m.Has(ModAlt) {
		parts = append(parts, "Alt")
	}
	if m.Has(ModShift) {
		parts = append(parts, "Shift")
	}
	if m.Has(ModSuper) {
		parts = append(parts, "Super")
	}
	if m.Has(ModCapsLock) {
		parts = append(parts, "CapsLock")
	}
	if m.Has(ModNumLock) {
		parts = append(parts, "NumLock")
	}

	return strings.Join(parts, "+")
}

func With

With returns a new Modifiers value with the specified modifier added.

func (m Modifiers) With(mod Modifiers) Modifiers {
	return m | mod
}

func Without

Without returns a new Modifiers value with the specified modifier removed.

func (m Modifiers) Without(mod Modifiers) Modifiers {
	return m &^ mod
}