Add presets for FH5 and Genshin Impact
This commit is contained in:
parent
dc0848a39c
commit
787b407110
4
app.go
4
app.go
|
@ -78,3 +78,7 @@ func (a *App) SetKey(device string, key int, target string) {
|
|||
// keyNum, _ := strconv.Atoi(key)
|
||||
devices.SetKey(deviceNum, key, target)
|
||||
}
|
||||
|
||||
func (a *App) UsePresetKeys(preset string) {
|
||||
devices.UsePreset(preset)
|
||||
}
|
||||
|
|
|
@ -40,3 +40,29 @@ var keymap = [][]string{
|
|||
{}, // device 0x07
|
||||
{}, // device 0x08
|
||||
}
|
||||
|
||||
var keymap_preset map[string]([][]string) = map[string]([][]string){
|
||||
"ForzaHorizon5": {
|
||||
{}, // left blank intentionally
|
||||
{"", "q", "e", "r", "w", "s", "a", "d", "enter"}, // device 0x01 (master)
|
||||
{"", "a", "b", "c", "up", "down", "left", "right", "enter"}, // device 0x02
|
||||
{}, // device 0x03
|
||||
{}, // device 0x04
|
||||
{}, // device 0x05
|
||||
{}, // device 0x06
|
||||
{}, // device 0x07
|
||||
{}, // device 0x08
|
||||
},
|
||||
"GenshinImpact": {
|
||||
{}, // left blank intentionally
|
||||
{"", "e", "q", "space", "w", "s", "a", "d", "lclick"}, // device 0x01 (master)
|
||||
{"", "1", "2", "3", "f", "", "", "", "rclick"}, // device 0x02
|
||||
{}, // device 0x03
|
||||
{}, // device 0x04
|
||||
{}, // device 0x05
|
||||
{}, // device 0x06
|
||||
{}, // device 0x07
|
||||
{}, // device 0x08
|
||||
},
|
||||
"ForestIceFire": {},
|
||||
}
|
||||
|
|
|
@ -0,0 +1,45 @@
|
|||
package devices
|
||||
|
||||
import (
|
||||
"log"
|
||||
|
||||
"github.com/go-vgo/robotgo"
|
||||
)
|
||||
|
||||
func pressKey(key string) {
|
||||
switch key {
|
||||
case "":
|
||||
return
|
||||
case "lclick":
|
||||
robotgo.Click("left", false)
|
||||
case "rclick":
|
||||
robotgo.Click("right", false)
|
||||
default:
|
||||
robotgo.KeyDown(key)
|
||||
}
|
||||
log.Printf("Key %s pressed", key)
|
||||
|
||||
}
|
||||
|
||||
func releaseKey(key string) {
|
||||
|
||||
switch key {
|
||||
case "":
|
||||
return
|
||||
case "lclick":
|
||||
case "rclick":
|
||||
default:
|
||||
robotgo.KeyUp(key)
|
||||
}
|
||||
log.Printf("Key %s released", key)
|
||||
}
|
||||
|
||||
func SetKey(device, key int, target string) {
|
||||
log.Printf("Set key %d of device %d to %s", key, device, target)
|
||||
keymap[device][key] = target
|
||||
}
|
||||
|
||||
func UsePreset(preset string) {
|
||||
log.Printf("Use preset %s", preset)
|
||||
keymap = keymap_preset[preset]
|
||||
}
|
|
@ -6,7 +6,6 @@ import (
|
|||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/go-vgo/robotgo"
|
||||
"go.bug.st/serial"
|
||||
)
|
||||
|
||||
|
@ -136,11 +135,9 @@ func RealtimeRead() {
|
|||
action := (int)(buf[3])
|
||||
switch action {
|
||||
case KeyActionPress:
|
||||
robotgo.KeyDown(keymap[device][key])
|
||||
log.Printf("Key %s pressed", keymap[device][key])
|
||||
pressKey(keymap[device][key])
|
||||
case KeyActionRelease:
|
||||
robotgo.KeyUp(keymap[device][key])
|
||||
log.Printf("Key %s released", keymap[device][key])
|
||||
releaseKey(keymap[device][key])
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -156,8 +153,3 @@ func GetDevices() []int {
|
|||
}
|
||||
return devices
|
||||
}
|
||||
|
||||
func SetKey(device, key int, target string) {
|
||||
log.Printf("Set key %d of device %d to %s", key, device, target)
|
||||
keymap[device][key] = target
|
||||
}
|
||||
|
|
|
@ -1,13 +1,14 @@
|
|||
<script setup>
|
||||
import { reactive } from 'vue'
|
||||
import { NButton, NInput, NAlert, NSpace, NSelect, useLoadingBar, NTabs, NTabPane, NH1, NText, NH2, NA } from 'naive-ui'
|
||||
import { GetDevices,SetKey } from '../../wailsjs/go/main/App'
|
||||
import { GetDevices, SetKey, UsePresetKeys } from '../../wailsjs/go/main/App'
|
||||
|
||||
var data = reactive({
|
||||
manualSelectDevice: null,
|
||||
manualSelectKey: null,
|
||||
computerKey:null,
|
||||
computerKey: null,
|
||||
availableDevices: [],
|
||||
presetApps: ["ForzaHorizon5", "GenshinImpact", "ForestIceFire"],
|
||||
availableKeys: [
|
||||
{
|
||||
type: "group",
|
||||
|
@ -65,8 +66,8 @@ function getDevices() {
|
|||
})
|
||||
}
|
||||
|
||||
function setKey(){
|
||||
SetKey(data.manualSelectDevice,data.manualSelectKey,data.computerKey)
|
||||
function setKey() {
|
||||
SetKey(data.manualSelectDevice, data.manualSelectKey, data.computerKey)
|
||||
}
|
||||
|
||||
</script>
|
||||
|
@ -82,12 +83,12 @@ function setKey(){
|
|||
预设
|
||||
</n-h2>
|
||||
<div class="m-2">
|
||||
<n-text>在下面寻找你玩的游戏,快速进行键位设置。</n-text>
|
||||
<n-text>在下面寻找你玩的游戏或使用场景,快速进行键位设置。</n-text>
|
||||
</div>
|
||||
<n-space align="center" justify="center">
|
||||
<n-button>《极限竞速:地平线5》</n-button>
|
||||
<n-button>《原神》</n-button>
|
||||
<n-button>《森林冰火人》</n-button>
|
||||
<n-button @click="UsePresetKeys(data.presetApps[0])">《极限竞速:地平线 5》</n-button>
|
||||
<n-button @click="UsePresetKeys(data.presetApps[1])">《原神》</n-button>
|
||||
<n-button @click="UsePresetKeys(data.presetApps[2])">《森林冰火人》</n-button>
|
||||
</n-space>
|
||||
<n-h2 class="text-left" prefix="bar">自定映射</n-h2>
|
||||
<div class="m-2">
|
||||
|
@ -106,6 +107,11 @@ function setKey(){
|
|||
<div class="m-2">
|
||||
<n-text>可用的按键名称请参见 </n-text>
|
||||
<n-a href="https://github.com/go-vgo/robotgo/blob/master/docs/keys.md" target="_blank">RobotGo 文档</n-a>
|
||||
<n-text>。<br />另外,软件也支持将 </n-text>
|
||||
<n-text code>lclick</n-text>
|
||||
<n-text> 与 </n-text>
|
||||
<n-text code>rclick</n-text>
|
||||
<n-text> 分别映射到左键与右键。</n-text>
|
||||
</div>
|
||||
</div>
|
||||
</main>
|
||||
|
|
|
@ -17,3 +17,5 @@ export function SetKey(arg1:string,arg2:number,arg3:string):void;
|
|||
export function StartListen():void;
|
||||
|
||||
export function StopListen():void;
|
||||
|
||||
export function UsePresetKeys(arg1:string):void;
|
||||
|
|
|
@ -33,3 +33,7 @@ export function StartListen() {
|
|||
export function StopListen() {
|
||||
return window['go']['main']['App']['StopListen']();
|
||||
}
|
||||
|
||||
export function UsePresetKeys(arg1) {
|
||||
return window['go']['main']['App']['UsePresetKeys'](arg1);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue