我正在研究一個跨平臺打字/按鍵模擬器。在這方面,我正在嘗試實現如下功能。package mainimport "fmt"import "strings"const ( VK_A = 5 VK_S = 14 VK_D = 25)func main() { // Suppose, I got user input "a", and based on this, // i want to print the value of VK_A var userInput string = "a" var constToSelect string = "VK_" + strings.ToUpper(userInput) fmt.Println(constToSelect) // This string is VK_A // But how can i get 5 which is the value of VK_A}我需要這種功能,因為根據平臺的不同,VK_A具有不同的值。對于窗戶來說,它是30,對于達爾文來說,它是0x00。
1 回答

HUH函數
TA貢獻1836條經驗 獲得超4個贊
您可以使用地圖并進行查找 https://blog.golang.org/maps
m = make(map[string]int)
m["VK_A"] = 5
value := m[constToSelect]
地圖不是常量
- 1 回答
- 0 關注
- 106 瀏覽
添加回答
舉報
0/150
提交
取消