input: Add numpad keys except for Edge browser (#580)

This commit is contained in:
Hajime Hoshi 2018-04-12 23:56:50 +09:00
parent 30cb4bad90
commit 5229e5a713
5 changed files with 149 additions and 0 deletions

View File

@ -82,6 +82,18 @@ func init() {
for i := 1; i <= 12; i++ {
nameToCodes["F"+strconv.Itoa(i)] = []string{"F" + strconv.Itoa(i)}
}
// Numpad
// https://www.w3.org/TR/uievents-code/#key-numpad-section
for c := '0'; c <= '9'; c++ {
nameToCodes["KP"+string(c)] = []string{"Numpad" + string(c)}
}
nameToCodes["KPDecimal"] = []string{"NumpadDecimal"}
nameToCodes["KPDivide"] = []string{"NumpadDivide"}
nameToCodes["KPMultiply"] = []string{"NumpadMultiply"}
nameToCodes["KPSubtract"] = []string{"NumpadSubtract"}
nameToCodes["KPAdd"] = []string{"NumpadAdd"}
nameToCodes["KPEnter"] = []string{"NumpadEnter"}
nameToCodes["KPEqual"] = []string{"NumpadEqual"}
}
func init() {
@ -129,6 +141,7 @@ func init() {
for i := 1; i <= 12; i++ {
keyCodeToNameEdge[0x70+i-1] = "F" + strconv.Itoa(i)
}
// TODO: Add numpad keys
}
const ebitenKeysTmpl = `{{.License}}

View File

@ -83,6 +83,23 @@ const (
KeyGraveAccent
KeyHome
KeyInsert
KeyKP0
KeyKP1
KeyKP2
KeyKP3
KeyKP4
KeyKP5
KeyKP6
KeyKP7
KeyKP8
KeyKP9
KeyKPAdd
KeyKPDecimal
KeyKPDivide
KeyKPEnter
KeyKPEqual
KeyKPMultiply
KeyKPSubtract
KeyLeft
KeyLeftBracket
KeyMinus

View File

@ -88,6 +88,23 @@ var glfwKeyCodeToKey = map[glfw.Key]Key{
glfw.KeyGraveAccent: KeyGraveAccent,
glfw.KeyHome: KeyHome,
glfw.KeyInsert: KeyInsert,
glfw.KeyKP0: KeyKP0,
glfw.KeyKP1: KeyKP1,
glfw.KeyKP2: KeyKP2,
glfw.KeyKP3: KeyKP3,
glfw.KeyKP4: KeyKP4,
glfw.KeyKP5: KeyKP5,
glfw.KeyKP6: KeyKP6,
glfw.KeyKP7: KeyKP7,
glfw.KeyKP8: KeyKP8,
glfw.KeyKP9: KeyKP9,
glfw.KeyKPAdd: KeyKPAdd,
glfw.KeyKPDecimal: KeyKPDecimal,
glfw.KeyKPDivide: KeyKPDivide,
glfw.KeyKPEnter: KeyKPEnter,
glfw.KeyKPEqual: KeyKPEqual,
glfw.KeyKPMultiply: KeyKPMultiply,
glfw.KeyKPSubtract: KeyKPSubtract,
glfw.KeyLeft: KeyLeft,
glfw.KeyLeftBracket: KeyLeftBracket,
glfw.KeyMinus: KeyMinus,

View File

@ -166,6 +166,57 @@ var keyToCodes = map[Key][]string{
KeyK: {
"KeyK",
},
KeyKP0: {
"Numpad0",
},
KeyKP1: {
"Numpad1",
},
KeyKP2: {
"Numpad2",
},
KeyKP3: {
"Numpad3",
},
KeyKP4: {
"Numpad4",
},
KeyKP5: {
"Numpad5",
},
KeyKP6: {
"Numpad6",
},
KeyKP7: {
"Numpad7",
},
KeyKP8: {
"Numpad8",
},
KeyKP9: {
"Numpad9",
},
KeyKPAdd: {
"NumpadAdd",
},
KeyKPDecimal: {
"NumpadDecimal",
},
KeyKPDivide: {
"NumpadDivide",
},
KeyKPEnter: {
"NumpadEnter",
},
KeyKPEqual: {
"NumpadEqual",
},
KeyKPMultiply: {
"NumpadMultiply",
},
KeyKPSubtract: {
"NumpadSubtract",
},
KeyL: {
"KeyL",
},

51
keys.go
View File

@ -93,6 +93,23 @@ const (
KeyGraveAccent Key = Key(input.KeyGraveAccent)
KeyHome Key = Key(input.KeyHome)
KeyInsert Key = Key(input.KeyInsert)
KeyKP0 Key = Key(input.KeyKP0)
KeyKP1 Key = Key(input.KeyKP1)
KeyKP2 Key = Key(input.KeyKP2)
KeyKP3 Key = Key(input.KeyKP3)
KeyKP4 Key = Key(input.KeyKP4)
KeyKP5 Key = Key(input.KeyKP5)
KeyKP6 Key = Key(input.KeyKP6)
KeyKP7 Key = Key(input.KeyKP7)
KeyKP8 Key = Key(input.KeyKP8)
KeyKP9 Key = Key(input.KeyKP9)
KeyKPAdd Key = Key(input.KeyKPAdd)
KeyKPDecimal Key = Key(input.KeyKPDecimal)
KeyKPDivide Key = Key(input.KeyKPDivide)
KeyKPEnter Key = Key(input.KeyKPEnter)
KeyKPEqual Key = Key(input.KeyKPEqual)
KeyKPMultiply Key = Key(input.KeyKPMultiply)
KeyKPSubtract Key = Key(input.KeyKPSubtract)
KeyLeft Key = Key(input.KeyLeft)
KeyLeftBracket Key = Key(input.KeyLeftBracket)
KeyMinus Key = Key(input.KeyMinus)
@ -240,6 +257,40 @@ func keyNameToKey(name string) (Key, bool) {
return KeyHome, true
case "insert":
return KeyInsert, true
case "kp0":
return KeyKP0, true
case "kp1":
return KeyKP1, true
case "kp2":
return KeyKP2, true
case "kp3":
return KeyKP3, true
case "kp4":
return KeyKP4, true
case "kp5":
return KeyKP5, true
case "kp6":
return KeyKP6, true
case "kp7":
return KeyKP7, true
case "kp8":
return KeyKP8, true
case "kp9":
return KeyKP9, true
case "kpadd":
return KeyKPAdd, true
case "kpdecimal":
return KeyKPDecimal, true
case "kpdivide":
return KeyKPDivide, true
case "kpenter":
return KeyKPEnter, true
case "kpequal":
return KeyKPEqual, true
case "kpmultiply":
return KeyKPMultiply, true
case "kpsubtract":
return KeyKPSubtract, true
case "left":
return KeyLeft, true
case "leftbracket":