Key remapping function

This commit is contained in:
cyp0633 2022-08-30 11:25:30 +08:00
parent 003edc1eac
commit dc0848a39c
Signed by: cyp0633
GPG Key ID: CF90D09FB1FDCE45
6 changed files with 26 additions and 5 deletions

7
app.go
View File

@ -3,6 +3,7 @@ package main
import (
"context"
"fmt"
"strconv"
"github.com/cyp0633/joycon-terminal/app"
"github.com/cyp0633/joycon-terminal/devices"
@ -71,3 +72,9 @@ func (a *App) Disconnect() {
a.StopListen()
devices.Conn.Close()
}
func (a *App) SetKey(device string, key int, target string) {
deviceNum, _ := strconv.Atoi(device)
// keyNum, _ := strconv.Atoi(key)
devices.SetKey(deviceNum, key, target)
}

View File

@ -17,7 +17,7 @@ func GetOnlineDevices() []SerialOptions {
log.Printf("list: %v", list)
for _, device := range list {
var children = SerialChoice{
Label: "设备" + strconv.Itoa(device),
Label: "设备 " + strconv.Itoa(device),
Value: strconv.Itoa(device),
Disabled: false,
}

View File

@ -156,3 +156,8 @@ 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
}

View File

@ -1,7 +1,7 @@
<script setup>
import { reactive } from 'vue'
import { NButton, NInput, NAlert, NSpace, NSelect, useLoadingBar, NTabs, NTabPane, NH1, NText, NH2, NA } from 'naive-ui'
import { GetDevices } from '../../wailsjs/go/main/App'
import { GetDevices,SetKey } from '../../wailsjs/go/main/App'
var data = reactive({
manualSelectDevice: null,
@ -66,7 +66,7 @@ function getDevices() {
}
function setKey(){
return
SetKey(data.manualSelectDevice,data.manualSelectKey,data.computerKey)
}
</script>
@ -89,7 +89,10 @@ function setKey(){
<n-button>原神</n-button>
<n-button>森林冰火人</n-button>
</n-space>
<n-h2 class="text-left" prefix="bar">手动调节</n-h2>
<n-h2 class="text-left" prefix="bar">自定映射</n-h2>
<div class="m-2">
<n-text>对于更广泛的用途您可以在这里自定义按键对应关系</n-text>
</div>
<div class="justify-center items-center flex flex-col">
<div class="grid grid-cols-2 content-center justify-center items-center gap-4 w-3/6">
<n-select children-field="children" label-field="label" value-field="value" filterable
@ -97,7 +100,7 @@ function setKey(){
@click="getDevices" />
<n-select children-field="children" label-field="label" value-field="value" filterable
:options="data.availableKeys" placeholder="选择按键" v-model:value="data.manualSelectKey" />
<n-input v-model:value="computerKey" type="text" placeholder="映射的 PC 按键"></n-input>
<n-input v-model:value="data.computerKey" type="text" placeholder="映射的 PC 按键"></n-input>
<n-button secondary type="primary" @click="setKey">设定</n-button>
</div>
<div class="m-2">

View File

@ -12,6 +12,8 @@ export function GetDevices():Promise<Array<app.SerialOptions>>;
export function Greet(arg1:string):Promise<string>;
export function SetKey(arg1:string,arg2:number,arg3:string):void;
export function StartListen():void;
export function StopListen():void;

View File

@ -22,6 +22,10 @@ export function Greet(arg1) {
return window['go']['main']['App']['Greet'](arg1);
}
export function SetKey(arg1, arg2, arg3) {
return window['go']['main']['App']['SetKey'](arg1, arg2, arg3);
}
export function StartListen() {
return window['go']['main']['App']['StartListen']();
}