Skip to content

Commit

Permalink
add symbol keys for platform/keyboard
Browse files Browse the repository at this point in the history
  • Loading branch information
jedipunkz authored and deadprogram committed Oct 28, 2020
1 parent c2689ef commit f2727ea
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 0 deletions.
30 changes: 30 additions & 0 deletions platforms/keyboard/keyboard.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@ const (
const (
Escape = 27
Spacebar = 32
Hyphen = 45
Asterisk = 42
Plus = 43
Slash = 47
Dot = 46
)

const (
Expand Down Expand Up @@ -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)
Expand Down
20 changes: 20 additions & 0 deletions platforms/keyboard/keyboard_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down

0 comments on commit f2727ea

Please sign in to comment.