Skip to content
This repository has been archived by the owner on Oct 7, 2023. It is now read-only.

Commit

Permalink
Add presets for FH5 and Genshin Impact
Browse files Browse the repository at this point in the history
  • Loading branch information
cyp0633 committed Aug 30, 2022
1 parent dc0848a commit 787b407
Show file tree
Hide file tree
Showing 7 changed files with 97 additions and 18 deletions.
4 changes: 4 additions & 0 deletions app.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
26 changes: 26 additions & 0 deletions devices/const.go
Original file line number Diff line number Diff line change
Expand Up @@ -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": {},
}
45 changes: 45 additions & 0 deletions devices/key.go
Original file line number Diff line number Diff line change
@@ -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]
}
12 changes: 2 additions & 10 deletions devices/serial.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"sync"
"time"

"github.com/go-vgo/robotgo"
"go.bug.st/serial"
)

Expand Down Expand Up @@ -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])
}
}
}
Expand All @@ -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
}
22 changes: 14 additions & 8 deletions frontend/src/components/Settings.vue
Original file line number Diff line number Diff line change
@@ -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",
Expand Down Expand Up @@ -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>
Expand All @@ -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">
Expand All @@ -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>
Expand Down
2 changes: 2 additions & 0 deletions frontend/wailsjs/go/main/App.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
4 changes: 4 additions & 0 deletions frontend/wailsjs/go/main/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

0 comments on commit 787b407

Please sign in to comment.