mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-24 10:48:53 +01:00
Arrange key's order
This commit is contained in:
parent
74e3c40740
commit
62d1395670
134
genkeys.go
134
genkeys.go
@ -35,38 +35,38 @@ var keyCodeToName map[int]string
|
||||
|
||||
func init() {
|
||||
keyCodeToName = map[int]string{
|
||||
0xBC: "KeyComma",
|
||||
0xBE: "KeyPeriod",
|
||||
0x12: "KeyLeftAlt",
|
||||
0x14: "KeyCapsLock",
|
||||
0x11: "KeyLeftControl",
|
||||
0x10: "KeyLeftShift",
|
||||
0x0D: "KeyEnter",
|
||||
0x20: "KeySpace",
|
||||
0x09: "KeyTab",
|
||||
0x2E: "KeyDelete",
|
||||
0x23: "KeyEnd",
|
||||
0x24: "KeyHome",
|
||||
0x2D: "KeyInsert",
|
||||
0x22: "KeyPageDown",
|
||||
0x21: "KeyPageUp",
|
||||
0x28: "KeyDown",
|
||||
0x25: "KeyLeft",
|
||||
0x27: "KeyRight",
|
||||
0x26: "KeyUp",
|
||||
0x1B: "KeyEscape",
|
||||
0xBC: "Comma",
|
||||
0xBE: "Period",
|
||||
0x12: "LeftAlt",
|
||||
0x14: "CapsLock",
|
||||
0x11: "LeftControl",
|
||||
0x10: "LeftShift",
|
||||
0x0D: "Enter",
|
||||
0x20: "Space",
|
||||
0x09: "Tab",
|
||||
0x2E: "Delete",
|
||||
0x23: "End",
|
||||
0x24: "Home",
|
||||
0x2D: "Insert",
|
||||
0x22: "PageDown",
|
||||
0x21: "PageUp",
|
||||
0x28: "Down",
|
||||
0x25: "Left",
|
||||
0x27: "Right",
|
||||
0x26: "Up",
|
||||
0x1B: "Escape",
|
||||
}
|
||||
// ASCII: 0 - 9
|
||||
for c := '0'; c <= '9'; c++ {
|
||||
keyCodeToName[int(c)] = "Key" + string(c)
|
||||
keyCodeToName[int(c)] = string(c)
|
||||
}
|
||||
// ASCII: A - Z
|
||||
for c := 'A'; c <= 'Z'; c++ {
|
||||
keyCodeToName[int(c)] = "Key" + string(c)
|
||||
keyCodeToName[int(c)] = string(c)
|
||||
}
|
||||
// Function keys
|
||||
for i := 1; i <= 12; i++ {
|
||||
keyCodeToName[0x70+i-1] = "KeyF" + strconv.Itoa(i)
|
||||
keyCodeToName[0x70+i-1] = "F" + strconv.Itoa(i)
|
||||
}
|
||||
}
|
||||
|
||||
@ -84,7 +84,7 @@ type Key int
|
||||
|
||||
// Keys
|
||||
const (
|
||||
{{range $index, $key := .KeyNames}}{{$key}} = Key(ui.{{$key}})
|
||||
{{range $index, $name := .KeyNames}}Key{{$name}} = Key(ui.Key{{$name}})
|
||||
{{end}}
|
||||
)
|
||||
`
|
||||
@ -96,7 +96,7 @@ package ui
|
||||
type Key int
|
||||
|
||||
const (
|
||||
{{range $index, $key := .KeyNames}}{{$key}}{{if eq $index 0}} Key = iota{{end}}
|
||||
{{range $index, $name := .KeyNames}}Key{{$name}}{{if eq $index 0}} Key = iota{{end}}
|
||||
{{end}}
|
||||
)
|
||||
`
|
||||
@ -112,7 +112,7 @@ import (
|
||||
)
|
||||
|
||||
var glfwKeyCodeToKey = map[glfw.Key]Key{
|
||||
{{range $index, $key := .KeyNames}}glfw.{{$key}}: {{$key}},
|
||||
{{range $index, $name := .KeyNames}}glfw.Key{{$name}}: Key{{$name}},
|
||||
{{end}}
|
||||
}
|
||||
`
|
||||
@ -124,11 +124,89 @@ const uiKeysJSTmpl = `{{.License}}
|
||||
package ui
|
||||
|
||||
var keyCodeToKey = map[int]Key{
|
||||
{{range $code, $name := .KeyCodeToName}}{{$code}}: {{$name}},
|
||||
{{range $code, $name := .KeyCodeToName}}{{$code}}: Key{{$name}},
|
||||
{{end}}
|
||||
}
|
||||
`
|
||||
|
||||
type KeyNames []string
|
||||
|
||||
func (k KeyNames) digit(name string) int {
|
||||
if len(name) != 1 {
|
||||
return -1
|
||||
}
|
||||
c := name[0]
|
||||
if c < '0' || '9' < c {
|
||||
return -1
|
||||
}
|
||||
return int(c - '0')
|
||||
}
|
||||
|
||||
func (k KeyNames) alphabet(name string) rune {
|
||||
if len(name) != 1 {
|
||||
return -1
|
||||
}
|
||||
c := rune(name[0])
|
||||
if c < 'A' || 'Z' < c {
|
||||
return -1
|
||||
}
|
||||
return c
|
||||
}
|
||||
|
||||
func (k KeyNames) function(name string) int {
|
||||
if len(name) < 2 {
|
||||
return -1
|
||||
}
|
||||
if name[0] != 'F' {
|
||||
return -1
|
||||
}
|
||||
i, err := strconv.Atoi(name[1:])
|
||||
if err != nil {
|
||||
return -1
|
||||
}
|
||||
return i
|
||||
}
|
||||
|
||||
func (k KeyNames) Len() int {
|
||||
return len(k)
|
||||
}
|
||||
|
||||
func (k KeyNames) Less(i, j int) bool {
|
||||
k0, k1 := k[i], k[j]
|
||||
d0, d1 := k.digit(k0), k.digit(k1)
|
||||
a0, a1 := k.alphabet(k0), k.alphabet(k1)
|
||||
f0, f1 := k.function(k0), k.function(k1)
|
||||
if d0 != -1 {
|
||||
if d1 != -1 {
|
||||
return d0 < d1
|
||||
}
|
||||
return true
|
||||
}
|
||||
if a0 != -1 {
|
||||
if d1 != -1 {
|
||||
return false
|
||||
}
|
||||
if a1 != -1 {
|
||||
return a0 < a1
|
||||
}
|
||||
return true
|
||||
}
|
||||
if d1 != -1 {
|
||||
return false
|
||||
}
|
||||
if a1 != -1 {
|
||||
return false
|
||||
}
|
||||
if f0 != -1 && f1 != -1 {
|
||||
return f0 < f1
|
||||
}
|
||||
return k0 < k1
|
||||
}
|
||||
|
||||
func (k KeyNames) Swap(i, j int) {
|
||||
k[i], k[j] = k[j], k[i]
|
||||
}
|
||||
|
||||
func main() {
|
||||
l, err := ioutil.ReadFile("license.txt")
|
||||
if err != nil {
|
||||
@ -143,7 +221,7 @@ func main() {
|
||||
names = append(names, name)
|
||||
codes = append(codes, code)
|
||||
}
|
||||
sort.Strings(names)
|
||||
sort.Sort(KeyNames(names))
|
||||
sort.Ints(codes)
|
||||
|
||||
for path, tmpl := range map[string]string{
|
||||
|
@ -30,20 +30,37 @@ const (
|
||||
KeyA
|
||||
KeyB
|
||||
KeyC
|
||||
KeyD
|
||||
KeyE
|
||||
KeyF
|
||||
KeyG
|
||||
KeyH
|
||||
KeyI
|
||||
KeyJ
|
||||
KeyK
|
||||
KeyL
|
||||
KeyM
|
||||
KeyN
|
||||
KeyO
|
||||
KeyP
|
||||
KeyQ
|
||||
KeyR
|
||||
KeyS
|
||||
KeyT
|
||||
KeyU
|
||||
KeyV
|
||||
KeyW
|
||||
KeyX
|
||||
KeyY
|
||||
KeyZ
|
||||
KeyCapsLock
|
||||
KeyComma
|
||||
KeyD
|
||||
KeyDelete
|
||||
KeyDown
|
||||
KeyE
|
||||
KeyEnd
|
||||
KeyEnter
|
||||
KeyEscape
|
||||
KeyF
|
||||
KeyF1
|
||||
KeyF10
|
||||
KeyF11
|
||||
KeyF12
|
||||
KeyF2
|
||||
KeyF3
|
||||
KeyF4
|
||||
@ -52,37 +69,20 @@ const (
|
||||
KeyF7
|
||||
KeyF8
|
||||
KeyF9
|
||||
KeyG
|
||||
KeyH
|
||||
KeyF10
|
||||
KeyF11
|
||||
KeyF12
|
||||
KeyHome
|
||||
KeyI
|
||||
KeyInsert
|
||||
KeyJ
|
||||
KeyK
|
||||
KeyL
|
||||
KeyLeft
|
||||
KeyLeftAlt
|
||||
KeyLeftControl
|
||||
KeyLeftShift
|
||||
KeyM
|
||||
KeyN
|
||||
KeyO
|
||||
KeyP
|
||||
KeyPageDown
|
||||
KeyPageUp
|
||||
KeyPeriod
|
||||
KeyQ
|
||||
KeyR
|
||||
KeyRight
|
||||
KeyS
|
||||
KeySpace
|
||||
KeyT
|
||||
KeyTab
|
||||
KeyU
|
||||
KeyUp
|
||||
KeyV
|
||||
KeyW
|
||||
KeyX
|
||||
KeyY
|
||||
KeyZ
|
||||
)
|
||||
|
@ -34,20 +34,37 @@ var glfwKeyCodeToKey = map[glfw.Key]Key{
|
||||
glfw.KeyA: KeyA,
|
||||
glfw.KeyB: KeyB,
|
||||
glfw.KeyC: KeyC,
|
||||
glfw.KeyD: KeyD,
|
||||
glfw.KeyE: KeyE,
|
||||
glfw.KeyF: KeyF,
|
||||
glfw.KeyG: KeyG,
|
||||
glfw.KeyH: KeyH,
|
||||
glfw.KeyI: KeyI,
|
||||
glfw.KeyJ: KeyJ,
|
||||
glfw.KeyK: KeyK,
|
||||
glfw.KeyL: KeyL,
|
||||
glfw.KeyM: KeyM,
|
||||
glfw.KeyN: KeyN,
|
||||
glfw.KeyO: KeyO,
|
||||
glfw.KeyP: KeyP,
|
||||
glfw.KeyQ: KeyQ,
|
||||
glfw.KeyR: KeyR,
|
||||
glfw.KeyS: KeyS,
|
||||
glfw.KeyT: KeyT,
|
||||
glfw.KeyU: KeyU,
|
||||
glfw.KeyV: KeyV,
|
||||
glfw.KeyW: KeyW,
|
||||
glfw.KeyX: KeyX,
|
||||
glfw.KeyY: KeyY,
|
||||
glfw.KeyZ: KeyZ,
|
||||
glfw.KeyCapsLock: KeyCapsLock,
|
||||
glfw.KeyComma: KeyComma,
|
||||
glfw.KeyD: KeyD,
|
||||
glfw.KeyDelete: KeyDelete,
|
||||
glfw.KeyDown: KeyDown,
|
||||
glfw.KeyE: KeyE,
|
||||
glfw.KeyEnd: KeyEnd,
|
||||
glfw.KeyEnter: KeyEnter,
|
||||
glfw.KeyEscape: KeyEscape,
|
||||
glfw.KeyF: KeyF,
|
||||
glfw.KeyF1: KeyF1,
|
||||
glfw.KeyF10: KeyF10,
|
||||
glfw.KeyF11: KeyF11,
|
||||
glfw.KeyF12: KeyF12,
|
||||
glfw.KeyF2: KeyF2,
|
||||
glfw.KeyF3: KeyF3,
|
||||
glfw.KeyF4: KeyF4,
|
||||
@ -56,37 +73,20 @@ var glfwKeyCodeToKey = map[glfw.Key]Key{
|
||||
glfw.KeyF7: KeyF7,
|
||||
glfw.KeyF8: KeyF8,
|
||||
glfw.KeyF9: KeyF9,
|
||||
glfw.KeyG: KeyG,
|
||||
glfw.KeyH: KeyH,
|
||||
glfw.KeyF10: KeyF10,
|
||||
glfw.KeyF11: KeyF11,
|
||||
glfw.KeyF12: KeyF12,
|
||||
glfw.KeyHome: KeyHome,
|
||||
glfw.KeyI: KeyI,
|
||||
glfw.KeyInsert: KeyInsert,
|
||||
glfw.KeyJ: KeyJ,
|
||||
glfw.KeyK: KeyK,
|
||||
glfw.KeyL: KeyL,
|
||||
glfw.KeyLeft: KeyLeft,
|
||||
glfw.KeyLeftAlt: KeyLeftAlt,
|
||||
glfw.KeyLeftControl: KeyLeftControl,
|
||||
glfw.KeyLeftShift: KeyLeftShift,
|
||||
glfw.KeyM: KeyM,
|
||||
glfw.KeyN: KeyN,
|
||||
glfw.KeyO: KeyO,
|
||||
glfw.KeyP: KeyP,
|
||||
glfw.KeyPageDown: KeyPageDown,
|
||||
glfw.KeyPageUp: KeyPageUp,
|
||||
glfw.KeyPeriod: KeyPeriod,
|
||||
glfw.KeyQ: KeyQ,
|
||||
glfw.KeyR: KeyR,
|
||||
glfw.KeyRight: KeyRight,
|
||||
glfw.KeyS: KeyS,
|
||||
glfw.KeySpace: KeySpace,
|
||||
glfw.KeyT: KeyT,
|
||||
glfw.KeyTab: KeyTab,
|
||||
glfw.KeyU: KeyU,
|
||||
glfw.KeyUp: KeyUp,
|
||||
glfw.KeyV: KeyV,
|
||||
glfw.KeyW: KeyW,
|
||||
glfw.KeyX: KeyX,
|
||||
glfw.KeyY: KeyY,
|
||||
glfw.KeyZ: KeyZ,
|
||||
}
|
||||
|
52
keys.go
52
keys.go
@ -36,20 +36,37 @@ const (
|
||||
KeyA = Key(ui.KeyA)
|
||||
KeyB = Key(ui.KeyB)
|
||||
KeyC = Key(ui.KeyC)
|
||||
KeyD = Key(ui.KeyD)
|
||||
KeyE = Key(ui.KeyE)
|
||||
KeyF = Key(ui.KeyF)
|
||||
KeyG = Key(ui.KeyG)
|
||||
KeyH = Key(ui.KeyH)
|
||||
KeyI = Key(ui.KeyI)
|
||||
KeyJ = Key(ui.KeyJ)
|
||||
KeyK = Key(ui.KeyK)
|
||||
KeyL = Key(ui.KeyL)
|
||||
KeyM = Key(ui.KeyM)
|
||||
KeyN = Key(ui.KeyN)
|
||||
KeyO = Key(ui.KeyO)
|
||||
KeyP = Key(ui.KeyP)
|
||||
KeyQ = Key(ui.KeyQ)
|
||||
KeyR = Key(ui.KeyR)
|
||||
KeyS = Key(ui.KeyS)
|
||||
KeyT = Key(ui.KeyT)
|
||||
KeyU = Key(ui.KeyU)
|
||||
KeyV = Key(ui.KeyV)
|
||||
KeyW = Key(ui.KeyW)
|
||||
KeyX = Key(ui.KeyX)
|
||||
KeyY = Key(ui.KeyY)
|
||||
KeyZ = Key(ui.KeyZ)
|
||||
KeyCapsLock = Key(ui.KeyCapsLock)
|
||||
KeyComma = Key(ui.KeyComma)
|
||||
KeyD = Key(ui.KeyD)
|
||||
KeyDelete = Key(ui.KeyDelete)
|
||||
KeyDown = Key(ui.KeyDown)
|
||||
KeyE = Key(ui.KeyE)
|
||||
KeyEnd = Key(ui.KeyEnd)
|
||||
KeyEnter = Key(ui.KeyEnter)
|
||||
KeyEscape = Key(ui.KeyEscape)
|
||||
KeyF = Key(ui.KeyF)
|
||||
KeyF1 = Key(ui.KeyF1)
|
||||
KeyF10 = Key(ui.KeyF10)
|
||||
KeyF11 = Key(ui.KeyF11)
|
||||
KeyF12 = Key(ui.KeyF12)
|
||||
KeyF2 = Key(ui.KeyF2)
|
||||
KeyF3 = Key(ui.KeyF3)
|
||||
KeyF4 = Key(ui.KeyF4)
|
||||
@ -58,37 +75,20 @@ const (
|
||||
KeyF7 = Key(ui.KeyF7)
|
||||
KeyF8 = Key(ui.KeyF8)
|
||||
KeyF9 = Key(ui.KeyF9)
|
||||
KeyG = Key(ui.KeyG)
|
||||
KeyH = Key(ui.KeyH)
|
||||
KeyF10 = Key(ui.KeyF10)
|
||||
KeyF11 = Key(ui.KeyF11)
|
||||
KeyF12 = Key(ui.KeyF12)
|
||||
KeyHome = Key(ui.KeyHome)
|
||||
KeyI = Key(ui.KeyI)
|
||||
KeyInsert = Key(ui.KeyInsert)
|
||||
KeyJ = Key(ui.KeyJ)
|
||||
KeyK = Key(ui.KeyK)
|
||||
KeyL = Key(ui.KeyL)
|
||||
KeyLeft = Key(ui.KeyLeft)
|
||||
KeyLeftAlt = Key(ui.KeyLeftAlt)
|
||||
KeyLeftControl = Key(ui.KeyLeftControl)
|
||||
KeyLeftShift = Key(ui.KeyLeftShift)
|
||||
KeyM = Key(ui.KeyM)
|
||||
KeyN = Key(ui.KeyN)
|
||||
KeyO = Key(ui.KeyO)
|
||||
KeyP = Key(ui.KeyP)
|
||||
KeyPageDown = Key(ui.KeyPageDown)
|
||||
KeyPageUp = Key(ui.KeyPageUp)
|
||||
KeyPeriod = Key(ui.KeyPeriod)
|
||||
KeyQ = Key(ui.KeyQ)
|
||||
KeyR = Key(ui.KeyR)
|
||||
KeyRight = Key(ui.KeyRight)
|
||||
KeyS = Key(ui.KeyS)
|
||||
KeySpace = Key(ui.KeySpace)
|
||||
KeyT = Key(ui.KeyT)
|
||||
KeyTab = Key(ui.KeyTab)
|
||||
KeyU = Key(ui.KeyU)
|
||||
KeyUp = Key(ui.KeyUp)
|
||||
KeyV = Key(ui.KeyV)
|
||||
KeyW = Key(ui.KeyW)
|
||||
KeyX = Key(ui.KeyX)
|
||||
KeyY = Key(ui.KeyY)
|
||||
KeyZ = Key(ui.KeyZ)
|
||||
)
|
||||
|
Loading…
Reference in New Issue
Block a user