2020-03-26 22:03:31 +00:00
|
|
|
package keys
|
|
|
|
|
|
|
|
import (
|
2020-06-06 13:43:11 +00:00
|
|
|
"fyne.io/fyne"
|
2020-03-26 22:03:31 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
2020-08-21 08:31:25 +00:00
|
|
|
//KCToASCII keycode to ascii table
|
|
|
|
KCToASCII map[Code]rune
|
2020-03-26 22:03:31 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
//GetASCIIForSC Returns Ascii for Scancode
|
2020-08-21 08:31:25 +00:00
|
|
|
func GetASCIIForSC(r uint16) uint16 {
|
|
|
|
return uint16(KCToASCII[Code(r)])
|
2020-03-26 22:03:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//GetSCForASCII Returns scancode For Ascii
|
2020-08-21 08:31:25 +00:00
|
|
|
func GetSCForASCII(r uint16) uint16 {
|
|
|
|
return uint16(ASCIIToKC[rune(r)])
|
2020-03-26 22:03:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func init() {
|
2020-08-21 08:31:25 +00:00
|
|
|
KCToASCII = make(map[Code]rune)
|
|
|
|
for x, y := range ASCIIToKC {
|
|
|
|
KCToASCII[y] = x
|
|
|
|
}
|
|
|
|
}
|
2020-03-26 22:03:31 +00:00
|
|
|
|
2020-08-21 08:31:25 +00:00
|
|
|
//CKIFyneKeyMap Control Keys interop
|
|
|
|
func CKIFyneKeyMap(e fyne.KeyName) uint16 {
|
|
|
|
if val, ok := KCToASCII[FyneToKC[e]]; ok {
|
|
|
|
return uint16(val)
|
|
|
|
}
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
|
|
|
//CKIKeyNameFromKC Key Name from Keycode
|
|
|
|
func CKIKeyNameFromKC(r uint16) string {
|
|
|
|
return Code(r).String()[4:]
|
|
|
|
}
|
2020-06-06 13:43:11 +00:00
|
|
|
|
2020-08-21 08:31:25 +00:00
|
|
|
//CKIKeyNameFromASCII key name from ascii code
|
|
|
|
func CKIKeyNameFromASCII(r uint16) string {
|
|
|
|
return ASCIIToKC[rune(r)].String()[4:]
|
2020-03-26 22:03:31 +00:00
|
|
|
}
|