// WriteByte processes a single byte from a UTF-8 byte string. This method is a
// stateful method with respect to the receiver Keyboard, meaning that its exact
// behavior will depend on the current state of its UTF-8 decode state machine:
//
//  (a) If the given byte is a valid ASCII encoding (0-127), then a keypress
//      sequence is immediately transmitted for the respective Keycode.
//
//  (b) If the given byte represents the final byte in a multi-byte codepoint,
//      then a keypress sequence is immediately transmitted by translating the
//      multi-byte codepoint to its respective Keycode.
//
//  (c) If the given byte appears to represent high bits for a multi-byte
//      codepoint, then the bits are copied to the receiver's internal state
//      machine buffer for use by a subsequent call to WriteByte() (or Write())
//      that completes the codepoint.
//
//  (d) If the given byte is out of range, or contains illegal bits for the
//      current state of the UTF-8 decoder, then the UTF-8 decode state machine
//      is reset to its initial state.
//
// In cases (c) and (d), a keypress sequence is not generated and no data is
// transmitted. In case (c), additional bytes must be received via WriteByte()
// (or Write()) to complete or discard the current codepoint.
WriteByte processes a single byte from a UTF-8 byte string. This method is a
stateful method with respect to the receiver Keyboard, meaning that its exact
behavior will depend on the current state of its UTF-8 decode state machine.

(a) If the given byte is a valid ASCII encoding (0-127), then a keypress
sequence is immediately transmitted for the respective Keycode.

(b) If the given byte represents the final byte in a multi-byte codepoint,
then a keypress sequence is immediately transmitted by translating the
multi-byte codepoint to its respective Keycode.

(c) If the given byte appears to represent high bits for a multi-byte
codepoint, then the bits are copied to the receiver's internal state
machine buffer for use by a subsequent call to WriteByte() (or Write())
that completes the codepoint.

(d) If the given byte is out of range, or contains illegal bits for the
current state of the UTF-8 decoder, then the UTF-8 decode state machine
is reset to its initial state.

In cases (c) and (d), a keypress sequence is not generated and no data is
transmitted. In case (c), additional bytes must be received via WriteByte()
(or Write()) to complete or discard the current codepoint.
// WriteByte processes a single byte from a UTF - 8 byte string . This method is a // stateful method with respect to the receiver Keyboard meaning that its exact // behavior will depend on the current state of its UTF - 8 decode state machine : // // ( a ) If the given byte is a valid ASCII encoding ( 0 - 127 ) then a keypress // sequence is immediately transmitted for the respective Keycode . // // ( b ) If the given byte represents the final byte in a multi - byte codepoint // then a keypress sequence is immediately transmitted by translating the // multi - byte codepoint to its respective Keycode . // // ( c ) If the given byte appears to represent high bits for a multi - byte // codepoint then the bits are copied to the receiver ' s internal state // machine buffer for use by a subsequent call to WriteByte () ( or Write () ) // that completes the codepoint . // // ( d ) If the given byte is out of range or contains illegal bits for the // current state of the UTF - 8 decoder then the UTF - 8 decode state machine // is reset to its initial state . // // In cases ( c ) and ( d ) a keypress sequence is not generated and no data is // transmitted . In case ( c ) additional bytes must be received via WriteByte () // ( or Write () ) to complete or discard the current codepoint .
func (kb *Keyboard) WriteByte(b byte) error {
	switch {
	case b < 0x80:
		kb.decode = decodeByte1
		return kb.write(uint16(b))
	case b < 0xC0:
		b = Keycode(b).key()
		switch kb.decode {
		case decodeByte2:
			kb.decode = decodeByte1
			return kb.write(kb.wideChar | uint16(b))
		case decodeByte3:
			kb.decode = decodeByte2
			kb.wideChar |= uint16(b) << 6
		}
	case b < 0xE0:
		kb.decode = decodeByte2
		kb.wideChar = uint16(b&0x1F) << 6
	case b < 0xF0:
		kb.decode = decodeByte3
		kb.wideChar = uint16(b&0x0F) << 12
	default:
		kb.decode = decodeReset
		return ErrInvalidUTF8
	}
	return nil
}
func ( kb * Keyboard ) WriteByte ( b byte ) error { switch { case b < 0x80 : kb . decode = decodeByte1 return kb . write ( uint16 ( b ) ) case b < 0xC0 : b = Keycode ( b ) . key ( ) switch kb . decode { case decodeByte2 : kb . decode = decodeByte1 return kb . write ( kb . wideChar | uint16 ( b ) ) case decodeByte3 : kb . decode = decodeByte2 kb . wideChar |= uint16 ( b ) << 6 } case b < 0xE0 : kb . decode = decodeByte2 kb . wideChar = uint16 ( b & 0x1F ) << 6 case b < 0xF0 : kb . decode = decodeByte3 kb . wideChar = uint16 ( b & 0x0F ) << 12 default : kb . decode = decodeReset return ErrInvalidUTF8 } return nil }
WriteByte processes a single byte from a UTF-8 byte string.
WriteByte processes a single byte from a UTF - 8 byte string .
// 1-byte encoding (0x00-0x7F) // 2nd, 3rd, or 4th byte (0x80-0xBF) // 2-byte encoding (0xC2-0xDF), or illegal byte 2 (0xC0-0xC1) // 3-byte encoding (0xE0-0xEF) // 4-byte encoding unsupported (0xF0-0xF4), or illegal byte 4 (0xF5-0xFF)