add symbol keys for platform/keyboard

This commit is contained in:
Tomokazu Hirai 2020-09-20 22:20:11 +09:00 committed by Ron Evans
parent c2689effd9
commit f2727eac4f
2 changed files with 50 additions and 0 deletions

View File

@ -47,6 +47,11 @@ const (
const (
Escape = 27
Spacebar = 32
Hyphen = 45
Asterisk = 42
Plus = 43
Slash = 47
Dot = 46
)
const (
@ -91,6 +96,31 @@ func Parse(input bytes) KeyEvent {
event.Key = Escape
}
// Hyphen
if code == Hyphen {
event.Key = Hyphen
}
// Asterisk
if code == Asterisk {
event.Key = Asterisk
}
// Plus
if code == Plus {
event.Key = Plus
}
// Slash
if code == Slash {
event.Key = Slash
}
// Dot
if code == Dot {
event.Key = Dot
}
// number keys
if code >= 48 && code <= 57 {
event.Key = int(code)

View File

@ -14,6 +14,26 @@ func TestParseEscape(t *testing.T) {
gobottest.Assert(t, Parse(bytes{27, 0, 0}).Key, Escape)
}
func TestParseHyphen(t *testing.T) {
gobottest.Assert(t, Parse(bytes{45, 0, 0}).Key, Escape)
}
func TestParseAsterisk(t *testing.T) {
gobottest.Assert(t, Parse(bytes{42, 0, 0}).Key, Escape)
}
func TestParsePlus(t *testing.T) {
gobottest.Assert(t, Parse(bytes{43, 0, 0}).Key, Escape)
}
func TestParseSlash(t *testing.T) {
gobottest.Assert(t, Parse(bytes{47, 0, 0}).Key, Escape)
}
func TestParseDot(t *testing.T) {
gobottest.Assert(t, Parse(bytes{46, 0, 0}).Key, Escape)
}
func TestParseNotEscape(t *testing.T) {
gobottest.Refute(t, Parse(bytes{27, 91, 65}).Key, Escape)
}