今天的token额度用完了,让Ai自己做的xbox支持库
本帖最后由 消散孤独 于 2026-9-9 12:06 编辑没有额度可以调试了,就这样吧放论坛里,以后想起来在搞吧。
<火山程序 类型 = "通常" 版本 = 1 />
包 Xbox支持
类 Xbox输入类 <公开
注释 = "Xbox支持库的输入类。通过C++桥接层调用Windows XInput,提供按键、扳机、摇杆、能力、电池、按键事件和音频设备查询;不负责蓝牙配对、连接或断开"
@视窗.外部头文件 = "native\\xbox_input_wrapper.h"
@视窗.外部源文件 = "native\\xbox_input_wrapper.cpp">
{
常量 按键方向上 <公开 静态 类型 = 整数 值 = 1>
常量 按键方向下 <公开 静态 类型 = 整数 值 = 2>
常量 按键方向左 <公开 静态 类型 = 整数 值 = 4>
常量 按键方向右 <公开 静态 类型 = 整数 值 = 8>
常量 按键开始 <公开 静态 类型 = 整数 值 = 16>
常量 按键返回 <公开 静态 类型 = 整数 值 = 32>
常量 按键左摇杆 <公开 静态 类型 = 整数 值 = 64>
常量 按键右摇杆 <公开 静态 类型 = 整数 值 = 128>
常量 按键左肩键 <公开 静态 类型 = 整数 值 = 256>
常量 按键右肩键 <公开 静态 类型 = 整数 值 = 512>
常量 按键系统指南 <公开 静态 类型 = 整数 值 = 1024>
常量 按键保留位 <公开 静态 类型 = 整数 值 = 2048>
常量 按键主键A <公开 静态 类型 = 整数 值 = 4096>
常量 按键主键B <公开 静态 类型 = 整数 值 = 8192>
常量 按键主键X <公开 静态 类型 = 整数 值 = 16384>
常量 按键主键Y <公开 静态 类型 = 整数 值 = 32768>
常量 事件虚拟键A <公开 静态 类型 = 整数 值 = 22528>
常量 事件虚拟键B <公开 静态 类型 = 整数 值 = 22529>
常量 事件虚拟键X <公开 静态 类型 = 整数 值 = 22530>
常量 事件虚拟键Y <公开 静态 类型 = 整数 值 = 22531>
常量 事件虚拟键右肩 <公开 静态 类型 = 整数 值 = 22532>
常量 事件虚拟键左肩 <公开 静态 类型 = 整数 值 = 22533>
常量 事件虚拟键左扳机 <公开 静态 类型 = 整数 值 = 22534>
常量 事件虚拟键右扳机 <公开 静态 类型 = 整数 值 = 22535>
常量 事件虚拟键方向上 <公开 静态 类型 = 整数 值 = 22544>
常量 事件虚拟键方向下 <公开 静态 类型 = 整数 值 = 22545>
常量 事件虚拟键方向左 <公开 静态 类型 = 整数 值 = 22546>
常量 事件虚拟键方向右 <公开 静态 类型 = 整数 值 = 22547>
常量 事件虚拟键开始 <公开 静态 类型 = 整数 值 = 22548>
常量 事件虚拟键返回 <公开 静态 类型 = 整数 值 = 22549>
常量 事件虚拟键左摇杆按下 <公开 静态 类型 = 整数 值 = 22550>
常量 事件虚拟键右摇杆按下 <公开 静态 类型 = 整数 值 = 22551>
常量 事件虚拟键左摇杆上 <公开 静态 类型 = 整数 值 = 22560>
常量 事件虚拟键左摇杆下 <公开 静态 类型 = 整数 值 = 22561>
常量 事件虚拟键左摇杆右 <公开 静态 类型 = 整数 值 = 22562>
常量 事件虚拟键左摇杆左 <公开 静态 类型 = 整数 值 = 22563>
常量 事件虚拟键左摇杆左上 <公开 静态 类型 = 整数 值 = 22564>
常量 事件虚拟键左摇杆右上 <公开 静态 类型 = 整数 值 = 22565>
常量 事件虚拟键左摇杆右下 <公开 静态 类型 = 整数 值 = 22566>
常量 事件虚拟键左摇杆左下 <公开 静态 类型 = 整数 值 = 22567>
常量 事件虚拟键右摇杆上 <公开 静态 类型 = 整数 值 = 22576>
常量 事件虚拟键右摇杆下 <公开 静态 类型 = 整数 值 = 22577>
常量 事件虚拟键右摇杆右 <公开 静态 类型 = 整数 值 = 22578>
常量 事件虚拟键右摇杆左 <公开 静态 类型 = 整数 值 = 22579>
常量 事件虚拟键右摇杆左上 <公开 静态 类型 = 整数 值 = 22580>
常量 事件虚拟键右摇杆右上 <公开 静态 类型 = 整数 值 = 22581>
常量 事件虚拟键右摇杆右下 <公开 静态 类型 = 整数 值 = 22582>
常量 事件虚拟键右摇杆左下 <公开 静态 类型 = 整数 值 = 22583>
常量 用户数量 <公开 静态 类型 = 整数 值 = 4>
常量 任意用户编号 <公开 静态 类型 = 整数 值 = 255>
常量 设备类型手柄 <公开 静态 类型 = 整数 值 = 1>
常量 能力查询默认标志 <公开 静态 类型 = 整数 值 = 0>
常量 查询标志手柄 <公开 静态 类型 = 整数 值 = 1>
常量 设备类型无线电池 <公开 静态 类型 = 整数 值 = 0>
常量 设备类型耳机电池 <公开 静态 类型 = 整数 值 = 1>
常量 电池类型无 <公开 静态 类型 = 整数 值 = 0>
常量 电池类型有线 <公开 静态 类型 = 整数 值 = 1>
常量 电池类型碱性 <公开 静态 类型 = 整数 值 = 2>
常量 电池类型镍氢 <公开 静态 类型 = 整数 值 = 3>
常量 电池电量空 <公开 静态 类型 = 整数 值 = 0>
常量 电池电量低 <公开 静态 类型 = 整数 值 = 1>
常量 电池电量中 <公开 静态 类型 = 整数 值 = 2>
常量 电池电量满 <公开 静态 类型 = 整数 值 = 3>
常量 按键事件按下 <公开 静态 类型 = 整数 值 = 1>
常量 按键事件释放 <公开 静态 类型 = 整数 值 = 2>
常量 按键事件重复 <公开 静态 类型 = 整数 值 = 4>
常量 错误函数不存在 <公开 静态 类型 = 整数 值 = 127>
常量 电池类型设备手柄 <公开 静态 类型 = 整数 值 = 0>
常量 电池类型设备耳机 <公开 静态 类型 = 整数 值 = 1>
常量 按键字段按键掩码 <公开 静态 类型 = 整数 值 = 0>
常量 按键字段左扳机 <公开 静态 类型 = 整数 值 = 1>
常量 按键字段右扳机 <公开 静态 类型 = 整数 值 = 2>
常量 按键字段左摇杆横 <公开 静态 类型 = 整数 值 = 3>
常量 按键字段左摇杆纵 <公开 静态 类型 = 整数 值 = 4>
常量 按键字段右摇杆横 <公开 静态 类型 = 整数 值 = 5>
常量 按键字段右摇杆纵 <公开 静态 类型 = 整数 值 = 6>
常量 按键字段数据包编号 <公开 静态 类型 = 整数 值 = 7>
常量 能力字段类型 <公开 静态 类型 = 整数 值 = 0>
常量 能力字段子类型 <公开 静态 类型 = 整数 值 = 1>
常量 能力字段标志 <公开 静态 类型 = 整数 值 = 2>
常量 能力字段左马达 <公开 静态 类型 = 整数 值 = 3>
常量 能力字段右马达 <公开 静态 类型 = 整数 值 = 4>
常量 按键事件字段虚拟键 <公开 静态 类型 = 整数 值 = 0>
常量 按键事件字段Unicode <公开 静态 类型 = 整数 值 = 1>
常量 按键事件字段标志 <公开 静态 类型 = 整数 值 = 2>
常量 按键事件字段用户编号 <公开 静态 类型 = 整数 值 = 3>
常量 按键事件字段HID码 <公开 静态 类型 = 整数 值 = 4>
常量 错误成功 <公开 静态 类型 = 整数 值 = 0>
常量 错误未连接 <公开 静态 类型 = 整数 值 = 1167>
常量 错误无效参数 <公开 静态 类型 = 整数 值 = 87>
常量 错误无数据 <公开 静态 类型 = 整数 值 = 4306>
常量 左摇杆死区 <公开 静态 类型 = 整数 值 = 7849>
常量 右摇杆死区 <公开 静态 类型 = 整数 值 = 8689>
常量 扳机死区 <公开 静态 类型 = 整数 值 = 30>
常量 能力类型未知 <公开 静态 类型 = 整数 值 = 0>
常量 能力类型游戏手柄 <公开 静态 类型 = 整数 值 = 1>
常量 能力子类型未知 <公开 静态 类型 = 整数 值 = 0>
常量 能力子类型游戏手柄 <公开 静态 类型 = 整数 值 = 1>
常量 能力子类型方向盘 <公开 静态 类型 = 整数 值 = 2>
常量 能力子类型街机摇杆 <公开 静态 类型 = 整数 值 = 3>
常量 能力子类型飞行摇杆 <公开 静态 类型 = 整数 值 = 4>
常量 能力子类型跳舞毯 <公开 静态 类型 = 整数 值 = 5>
常量 能力子类型吉他 <公开 静态 类型 = 整数 值 = 6>
常量 能力子类型备用吉他 <公开 静态 类型 = 整数 值 = 7>
常量 能力子类型贝斯吉他 <公开 静态 类型 = 整数 值 = 8>
常量 能力子类型街机手柄 <公开 静态 类型 = 整数 值 = 9>
常量 能力标志强制反馈 <公开 静态 类型 = 整数 值 = 1>
常量 能力标志无线 <公开 静态 类型 = 整数 值 = 2>
常量 能力标志语音 <公开 静态 类型 = 整数 值 = 4>
常量 能力标志电源管理 <公开 静态 类型 = 整数 值 = 8>
常量 能力标志无导航键 <公开 静态 类型 = 整数 值 = 16>
方法 取状态字段 <公开 静态 类型 = 整数 @嵌入式方法 = "" @禁止流程检查 = 真>
注释 = "读取指定用户的状态字段。字段0为按键,1/2为扳机,3到6为摇杆,7为数据包编号;返回0表示成功,1167表示未连接"
参数 用户编号 <类型 = 整数>
参数 字段 <类型 = 整数>
{
@ return XboxInput_GetValue((unsigned int)@<用户编号>, (int)@<字段>);
}
方法 取按键 <公开 静态 类型 = 整数 @嵌入式方法 = "" @禁止流程检查 = 真>
参数 用户编号 <类型 = 整数>
{
@ return XboxInput_GetValue((unsigned int)@<用户编号>, 0);
}
方法 取左扳机 <公开 静态 类型 = 整数 @嵌入式方法 = "" @禁止流程检查 = 真>
参数 用户编号 <类型 = 整数>
{
@ return XboxInput_GetValue((unsigned int)@<用户编号>, 1);
}
方法 取右扳机 <公开 静态 类型 = 整数 @嵌入式方法 = "" @禁止流程检查 = 真>
参数 用户编号 <类型 = 整数>
{
@ return XboxInput_GetValue((unsigned int)@<用户编号>, 2);
}
方法 取左摇杆横 <公开 静态 类型 = 整数 @嵌入式方法 = "" @禁止流程检查 = 真>
参数 用户编号 <类型 = 整数>
{
@ return XboxInput_GetValue((unsigned int)@<用户编号>, 3);
}
方法 取左摇杆纵 <公开 静态 类型 = 整数 @嵌入式方法 = "" @禁止流程检查 = 真>
参数 用户编号 <类型 = 整数>
{
@ return XboxInput_GetValue((unsigned int)@<用户编号>, 4);
}
方法 取右摇杆横 <公开 静态 类型 = 整数 @嵌入式方法 = "" @禁止流程检查 = 真>
参数 用户编号 <类型 = 整数>
{
@ return XboxInput_GetValue((unsigned int)@<用户编号>, 5);
}
方法 取右摇杆纵 <公开 静态 类型 = 整数 @嵌入式方法 = "" @禁止流程检查 = 真>
参数 用户编号 <类型 = 整数>
{
@ return XboxInput_GetValue((unsigned int)@<用户编号>, 6);
}
方法 取数据包编号 <公开 静态 类型 = 整数 @嵌入式方法 = "" @禁止流程检查 = 真>
参数 用户编号 <类型 = 整数>
{
@ return XboxInput_GetValue((unsigned int)@<用户编号>, 7);
}
方法 置震动 <公开 静态 类型 = 整数 @嵌入式方法 = "" @禁止流程检查 = 真>
注释 = "设置左右震动马达,强度范围0到65535;返回0表示成功"
参数 用户编号 <类型 = 整数>
参数 左马达 <类型 = 整数>
参数 右马达 <类型 = 整数>
{
@ return XboxInput_SetVibration((unsigned int)@<用户编号>, (unsigned short)@<左马达>, (unsigned short)@<右马达>);
}
方法 取能力字段 <公开 静态 类型 = 整数 @嵌入式方法 = "" @禁止流程检查 = 真>
注释 = "读取手柄能力字段。字段0类型、1子类型、2标志、3左马达、4右马达"
参数 用户编号 <类型 = 整数>
参数 查询标志 <类型 = 整数>
参数 字段 <类型 = 整数>
{
@ return XboxInput_GetCapabilitiesValue((unsigned int)@<用户编号>, (unsigned int)@<查询标志>, (int)@<字段>);
}
方法 取能力类型 <公开 静态 类型 = 整数 @嵌入式方法 = "" @禁止流程检查 = 真>
参数 用户编号 <类型 = 整数>
{
@ return XboxInput_GetCapabilitiesValue((unsigned int)@<用户编号>, 0, 0);
}
方法 取能力子类型 <公开 静态 类型 = 整数 @嵌入式方法 = "" @禁止流程检查 = 真>
参数 用户编号 <类型 = 整数>
{
@ return XboxInput_GetCapabilitiesValue((unsigned int)@<用户编号>, 0, 1);
}
方法 取能力标志 <公开 静态 类型 = 整数 @嵌入式方法 = "" @禁止流程检查 = 真>
参数 用户编号 <类型 = 整数>
{
@ return XboxInput_GetCapabilitiesValue((unsigned int)@<用户编号>, 0, 2);
}
方法 取能力左马达 <公开 静态 类型 = 整数 @嵌入式方法 = "" @禁止流程检查 = 真>
参数 用户编号 <类型 = 整数>
{
@ return XboxInput_GetCapabilitiesValue((unsigned int)@<用户编号>, 0, 3);
}
方法 取能力右马达 <公开 静态 类型 = 整数 @嵌入式方法 = "" @禁止流程检查 = 真>
参数 用户编号 <类型 = 整数>
{
@ return XboxInput_GetCapabilitiesValue((unsigned int)@<用户编号>, 0, 4);
}
方法 取电池类型 <公开 静态 类型 = 整数 @嵌入式方法 = "" @禁止流程检查 = 真>
参数 用户编号 <类型 = 整数>
参数 设备类型 <类型 = 整数>
{
@ return XboxInput_GetBatteryValue((unsigned int)@<用户编号>, (int)@<设备类型>, 0);
}
方法 取电池电量 <公开 静态 类型 = 整数 @嵌入式方法 = "" @禁止流程检查 = 真>
参数 用户编号 <类型 = 整数>
参数 设备类型 <类型 = 整数>
{
@ return XboxInput_GetBatteryValue((unsigned int)@<用户编号>, (int)@<设备类型>, 1);
}
方法 取按键事件 <公开 静态 类型 = 整数 @嵌入式方法 = "" @禁止流程检查 = 真>
参数 用户编号 <类型 = 整数>
参数 保留值 <类型 = 整数>
参数 取值类型 <类型 = 整数>
{
@ return XboxInput_GetKeystrokeValue((unsigned int)@<用户编号>, (int)@<保留值>, (int)@<取值类型>);
}
方法 取电池字段 <公开 静态 类型 = 整数 @嵌入式方法 = "" @禁止流程检查 = 真>
注释 = "读取电池字段。字段0为电池类型,字段1为电量等级;设备类型0为手柄,1为耳机"
参数 用户编号 <类型 = 整数>
参数 设备类型 <类型 = 整数>
参数 字段 <类型 = 整数>
{
@ return XboxInput_GetBatteryValue((unsigned int)@<用户编号>, (int)@<设备类型>, (int)@<字段>);
}
方法 取按键事件字段 <公开 静态 类型 = 整数 @嵌入式方法 = "" @禁止流程检查 = 真>
注释 = "读取按键事件字段。字段0虚拟键、1 Unicode、2标志、3用户编号、4 HID码"
参数 用户编号 <类型 = 整数>
参数 保留值 <类型 = 整数>
参数 字段 <类型 = 整数>
{
@ return XboxInput_GetKeystrokeValue((unsigned int)@<用户编号>, (int)@<保留值>, (int)@<字段>);
}
方法 置输入启用 <公开 静态 类型 = 整数 @嵌入式方法 = "" @禁止流程检查 = 真>
注释 = "启用或禁用XInput输入处理;这不是连接或断开手柄"
参数 启用 <类型 = 逻辑型>
{
@ return XboxInput_Enable(@<启用> ? 1 : 0);
}
方法 取音频设备ID <公开 静态 类型 = 文本型 @嵌入式方法 = "" @禁止流程检查 = 真>
注释 = "获取手柄关联的音频设备ID。取渲染设备为真返回播放设备,否则返回采集设备"
参数 用户编号 <类型 = 整数>
参数 取渲染设备 <类型 = 逻辑型>
{
@ return CVolString(XboxInput_GetAudioDeviceId((unsigned int)@<用户编号>, @<取渲染设备> ? 1 : 0));
}
方法 取音频设备GUID <公开 静态 类型 = 文本型 @嵌入式方法 = "" @禁止流程检查 = 真>
注释 = "获取手柄关联的DirectSound设备GUID;系统不支持时返回空文本"
参数 用户编号 <类型 = 整数>
参数 取渲染设备 <类型 = 逻辑型>
{
@ return CVolString(XboxInput_GetAudioDeviceGuid((unsigned int)@<用户编号>, @<取渲染设备> ? 1 : 0));
}
}
类 Xbox设置类 <公开
注释 = "Xbox支持库的设置类。通过C++桥接层调用XInputSetState和XInputEnable,提供震动及输入启用控制;禁用输入不等于断开手柄"
@视窗.外部头文件 = "native\\xbox_input_wrapper.h"
@视窗.外部源文件 = "native\\xbox_input_wrapper.cpp">
{
常量 错误成功 <公开 静态 类型 = 整数 值 = 0>
常量 错误未连接 <公开 静态 类型 = 整数 值 = 1167>
常量 错误无效参数 <公开 静态 类型 = 整数 值 = 87>
常量 错误函数不存在 <公开 静态 类型 = 整数 值 = 127>
常量 错误无数据 <公开 静态 类型 = 整数 值 = 4306>
常量 最大马达强度 <公开 静态 类型 = 整数 值 = 65535>
常量 最大用户编号 <公开 静态 类型 = 整数 值 = 3>
常量 用户数量 <公开 静态 类型 = 整数 值 = 4>
常量 任意用户编号 <公开 静态 类型 = 整数 值 = 255>
方法 设置震动 <公开 静态 类型 = 整数 @嵌入式方法 = "" @禁止流程检查 = 真>
注释 = "设置指定手柄的左右马达强度,范围0到65535"
参数 用户编号 <类型 = 整数>
参数 左马达强度 <类型 = 整数>
参数 右马达强度 <类型 = 整数>
{
@ return XboxInput_SetVibration((unsigned int)@<用户编号>, (unsigned short)@<左马达强度>, (unsigned short)@<右马达强度>);
}
方法 停止震动 <公开 静态 类型 = 整数 @嵌入式方法 = "" @禁止流程检查 = 真>
注释 = "将指定手柄的左右震动马达都设为0"
参数 用户编号 <类型 = 整数>
{
@ return XboxInput_SetVibration((unsigned int)@<用户编号>, 0, 0);
}
方法 设置输入启用 <公开 静态 类型 = 整数 @嵌入式方法 = "" @禁止流程检查 = 真>
注释 = "启用或禁用输入处理,不会改变Windows设备连接状态"
参数 启用 <类型 = 逻辑型>
{
@ return XboxInput_Enable(@<启用> ? 1 : 0);
}
方法 启用输入 <公开 静态 类型 = 整数 @嵌入式方法 = "" @禁止流程检查 = 真>
{
@ return XboxInput_Enable(1);
}
方法 禁用输入 <公开 静态 类型 = 整数 @嵌入式方法 = "" @禁止流程检查 = 真>
{
@ return XboxInput_Enable(0);
}
}
类 Xbox按键设置类 <公开
注释 = "Xbox支持库的应用层按键映射类。C++桥接层保存映射表并转换按键掩码,不修改手柄固件、Windows蓝牙连接或其他程序的输入"
@视窗.外部头文件 = "native\\xbox_input_wrapper.h"
@视窗.外部源文件 = "native\\xbox_input_wrapper.cpp">
{
常量 错误成功 <公开 静态 类型 = 整数 值 = 0>
常量 错误无效参数 <公开 静态 类型 = 整数 值 = 87>
常量 按键方向上 <公开 静态 类型 = 整数 值 = 1>
常量 按键方向下 <公开 静态 类型 = 整数 值 = 2>
常量 按键方向左 <公开 静态 类型 = 整数 值 = 4>
常量 按键方向右 <公开 静态 类型 = 整数 值 = 8>
常量 按键开始 <公开 静态 类型 = 整数 值 = 16>
常量 按键返回 <公开 静态 类型 = 整数 值 = 32>
常量 按键左摇杆 <公开 静态 类型 = 整数 值 = 64>
常量 按键右摇杆 <公开 静态 类型 = 整数 值 = 128>
常量 按键左肩键 <公开 静态 类型 = 整数 值 = 256>
常量 按键右肩键 <公开 静态 类型 = 整数 值 = 512>
常量 按键系统指南 <公开 静态 类型 = 整数 值 = 1024>
常量 按键保留位 <公开 静态 类型 = 整数 值 = 2048>
常量 按键主键A <公开 静态 类型 = 整数 值 = 4096>
常量 按键主键B <公开 静态 类型 = 整数 值 = 8192>
常量 按键主键X <公开 静态 类型 = 整数 值 = 16384>
常量 按键主键Y <公开 静态 类型 = 整数 值 = 32768>
方法 设置按键映射 <公开 静态 类型 = 整数 @嵌入式方法 = "" @禁止流程检查 = 真>
注释 = "设置应用层按键映射,不会修改手柄硬件布局或系统蓝牙连接"
参数 原按键 <类型 = 整数>
参数 目标按键 <类型 = 整数>
{
@ return XboxInput_SetButtonMapping((unsigned short)@<原按键>, (unsigned short)@<目标按键>);
}
方法 清除按键映射 <公开 静态 类型 = 整数 @嵌入式方法 = "" @禁止流程检查 = 真>
参数 原按键 <类型 = 整数>
{
@ return XboxInput_ClearButtonMapping((unsigned short)@<原按键>);
}
方法 重置全部映射 <公开 静态 @嵌入式方法 = "" @禁止流程检查 = 真>
{
@ XboxInput_ResetButtonMappings();
}
方法 转换按键 <公开 静态 类型 = 整数 @嵌入式方法 = "" @禁止流程检查 = 真>
注释 = "将读取到的原始按键掩码转换为当前应用层映射后的掩码"
参数 原始按键 <类型 = 整数>
{
@ return (int)XboxInput_ApplyButtonMappings((unsigned int)@<原始按键>);
}
}
类 Xbox设备能力类 <公开
注释 = "Xbox支持库的设备能力类。通过C++桥接层读取无线、语音、电源管理和电池能力;无线标志只表示能力,不提供蓝牙扫描、配对、连接或断开"
@视窗.外部头文件 = "native\\xbox_input_wrapper.h"
@视窗.外部源文件 = "native\\xbox_input_wrapper.cpp">
{
方法 取是否支持无线 <公开 静态 类型 = 逻辑型 @嵌入式方法 = "" @禁止流程检查 = 真>
注释 = "查询能力标志中的无线支持;XInput不提供蓝牙扫描、配对、连接或断开"
参数 用户编号 <类型 = 整数>
{
@ return (XboxInput_GetCapabilitiesValue((unsigned int)@<用户编号>, 0, 2) & 2) != 0;
}
方法 取是否支持语音 <公开 静态 类型 = 逻辑型 @嵌入式方法 = "" @禁止流程检查 = 真>
参数 用户编号 <类型 = 整数>
{
@ return (XboxInput_GetCapabilitiesValue((unsigned int)@<用户编号>, 0, 2) & 4) != 0;
}
方法 取是否支持电源管理 <公开 静态 类型 = 逻辑型 @嵌入式方法 = "" @禁止流程检查 = 真>
参数 用户编号 <类型 = 整数>
{
@ return (XboxInput_GetCapabilitiesValue((unsigned int)@<用户编号>, 0, 2) & 8) != 0;
}
方法 取电池类型 <公开 静态 类型 = 整数 @嵌入式方法 = "" @禁止流程检查 = 真>
参数 用户编号 <类型 = 整数>
参数 设备类型 <类型 = 整数>
{
@ return XboxInput_GetBatteryValue((unsigned int)@<用户编号>, (int)@<设备类型>, 0);
}
方法 取电池电量 <公开 静态 类型 = 整数 @嵌入式方法 = "" @禁止流程检查 = 真>
参数 用户编号 <类型 = 整数>
参数 设备类型 <类型 = 整数>
{
@ return XboxInput_GetBatteryValue((unsigned int)@<用户编号>, (int)@<设备类型>, 1);
}
方法 取能力字段 <公开 静态 类型 = 整数 @嵌入式方法 = "" @禁止流程检查 = 真>
参数 用户编号 <类型 = 整数>
参数 查询标志 <类型 = 整数>
参数 字段 <类型 = 整数>
{
@ return XboxInput_GetCapabilitiesValue((unsigned int)@<用户编号>, (unsigned int)@<查询标志>, (int)@<字段>);
}
}
xbox_input_wrapper.cpp#include "xbox_input_wrapper.h"
#include <objbase.h>
#include <vector>
#pragma comment(lib, "ole32.lib")
// 这里复制XInput公开结构体的ABI布局,避免要求用户额外安装Xbox SDK。
// 所有结构体大小在下方用static_assert校验,防止桥接层与系统DLL布局不一致。
struct XboxInputGamepad {
unsigned short wButtons;
unsigned char bLeftTrigger;
unsigned char bRightTrigger;
short sThumbLX;
short sThumbLY;
short sThumbRX;
short sThumbRY;
};
struct XboxInputState {
unsigned int dwPacketNumber;
XboxInputGamepad Gamepad;
};
struct XboxInputVibration {
unsigned short wLeftMotorSpeed;
unsigned short wRightMotorSpeed;
};
struct XboxInputCapabilities {
unsigned char type;
unsigned char subType;
unsigned short flags;
XboxInputGamepad Gamepad;
XboxInputVibration Vibration;
};
struct XboxInputBatteryInformation {
unsigned char batteryType;
unsigned char batteryLevel;
};
struct XboxInputKeystroke {
unsigned short virtualKey;
unsigned short unicode;
unsigned short flags;
unsigned char userIndex;
unsigned char hidCode;
};
static_assert(sizeof(XboxInputGamepad) == 12, "XINPUT_GAMEPAD ABI mismatch");
static_assert(sizeof(XboxInputState) == 16, "XINPUT_STATE ABI mismatch");
static_assert(sizeof(XboxInputVibration) == 4, "XINPUT_VIBRATION ABI mismatch");
static_assert(sizeof(XboxInputCapabilities) == 20, "XINPUT_CAPABILITIES ABI mismatch");
static_assert(sizeof(XboxInputBatteryInformation) == 2, "XINPUT_BATTERY_INFORMATION ABI mismatch");
static_assert(sizeof(XboxInputKeystroke) == 8, "XINPUT_KEYSTROKE ABI mismatch");
// Windows XInput函数指针类型。系统DLL通过LoadLibraryW/GetProcAddress动态加载,
// 因此类库不需要把xinput1_4.lib放入用户工程。
typedef unsigned long (WINAPI* XboxInputGetStateProc)(
unsigned int, XboxInputState*);
typedef unsigned long (WINAPI* XboxInputSetStateProc)(
unsigned int, const XboxInputVibration*);
typedef unsigned long (WINAPI* XboxInputGetCapabilitiesProc)(
unsigned int, unsigned int, XboxInputCapabilities*);
typedef unsigned long (WINAPI* XboxInputGetBatteryInformationProc)(
unsigned int, unsigned char, XboxInputBatteryInformation*);
typedef unsigned long (WINAPI* XboxInputGetKeystrokeProc)(
unsigned int, unsigned int, XboxInputKeystroke*);
typedef void (WINAPI* XboxInputEnableProc)(int);
typedef unsigned long (WINAPI* XboxInputGetAudioGuidsProc)(
unsigned int, GUID*, GUID*);
typedef unsigned long (WINAPI* XboxInputGetAudioIdsProc)(
unsigned int, wchar_t*, unsigned int*, wchar_t*, unsigned int*);
static HMODULE XboxInput_Module()
{
// Windows 8及以上通常提供xinput1_4.dll;加载失败时上层返回1167。
static HMODULE module = LoadLibraryW(L"xinput1_4.dll");
return module;
}
static HMODULE XboxInput_LegacyModule()
{
// 仅用于兼容旧系统的DirectSound GUID查询,不承担核心输入功能。
static HMODULE module = LoadLibraryW(L"xinput1_3.dll");
return module;
}
static unsigned short XboxInput_ButtonMappings = {
1, 2, 4, 8, 16, 32, 64, 128,
256, 512, 1024, 2048, 4096, 8192, 16384, 32768
};
static int XboxInput_ButtonIndex(unsigned short button)
{
if (button == 0 || (button & (button - 1)) != 0)
return -1;
int index = 0;
while ((button >>= 1) != 0)
++index;
return index;
}
int XboxInput_GetValue(unsigned int userIndex, int valueKind)
{
// 这是火山Xbox输入类的主要入口:调用XInputGetState并拆出一个字段。
HMODULE module = XboxInput_Module();
if (module == NULL)
return 1167;
XboxInputGetStateProc getState =
reinterpret_cast<XboxInputGetStateProc>(
GetProcAddress(module, "XInputGetState"));
if (getState == NULL)
return 127;
XboxInputState state = {};
unsigned long result = getState(userIndex, &state);
if (result != 0)
return static_cast<int>(result);
switch (valueKind) {
case 0: return static_cast<int>(state.Gamepad.wButtons);
case 1: return static_cast<int>(state.Gamepad.bLeftTrigger);
case 2: return static_cast<int>(state.Gamepad.bRightTrigger);
case 3: return static_cast<int>(state.Gamepad.sThumbLX);
case 4: return static_cast<int>(state.Gamepad.sThumbLY);
case 5: return static_cast<int>(state.Gamepad.sThumbRX);
case 6: return static_cast<int>(state.Gamepad.sThumbRY);
case 7: return static_cast<int>(state.dwPacketNumber);
default: return 87;
}
}
int XboxInput_SetVibration(
unsigned int userIndex,
unsigned short leftMotor,
unsigned short rightMotor)
{
// 震动属于XInput输出能力;它不会改变连接状态。
HMODULE module = XboxInput_Module();
if (module == NULL)
return 1167;
XboxInputSetStateProc setState =
reinterpret_cast<XboxInputSetStateProc>(
GetProcAddress(module, "XInputSetState"));
if (setState == NULL)
return 127;
XboxInputVibration vibration = {leftMotor, rightMotor};
return static_cast<int>(setState(userIndex, &vibration));
}
int XboxInput_SetButtonMapping(
unsigned short sourceButton,
unsigned short targetButton)
{
// 映射只在本C++桥接层保存,应用读取按键后再调用ApplyButtonMappings。
int sourceIndex = XboxInput_ButtonIndex(sourceButton);
if (sourceIndex < 0 || XboxInput_ButtonIndex(targetButton) < 0)
return 87;
XboxInput_ButtonMappings = targetButton;
return 0;
}
int XboxInput_ClearButtonMapping(unsigned short sourceButton)
{
int sourceIndex = XboxInput_ButtonIndex(sourceButton);
if (sourceIndex < 0)
return 87;
XboxInput_ButtonMappings = sourceButton;
return 0;
}
void XboxInput_ResetButtonMappings()
{
for (int index = 0; index < 16; ++index)
XboxInput_ButtonMappings =
static_cast<unsigned short>(1u << index);
}
unsigned int XboxInput_ApplyButtonMappings(unsigned int buttons)
{
unsigned int mappedButtons = 0;
for (int index = 0; index < 16; ++index) {
unsigned int sourceButton = 1u << index;
if ((buttons & sourceButton) != 0)
mappedButtons |= XboxInput_ButtonMappings;
}
return mappedButtons;
}
int XboxInput_GetCapabilitiesValue(unsigned int userIndex, unsigned int flags, int valueKind)
{
// 能力查询可判断无线/语音/电源管理等标志,但不提供蓝牙管理API。
HMODULE module = XboxInput_Module();
if (module == NULL) return 1167;
XboxInputGetCapabilitiesProc getCapabilities =
reinterpret_cast<XboxInputGetCapabilitiesProc>(
GetProcAddress(module, "XInputGetCapabilities"));
if (getCapabilities == NULL) return 127;
XboxInputCapabilities capabilities = {};
unsigned long result = getCapabilities(userIndex, flags, &capabilities);
if (result != 0) return static_cast<int>(result);
switch (valueKind) {
case 0: return capabilities.type;
case 1: return capabilities.subType;
case 2: return capabilities.flags;
case 3: return capabilities.Vibration.wLeftMotorSpeed;
case 4: return capabilities.Vibration.wRightMotorSpeed;
default: return 87;
}
}
int XboxInput_GetBatteryValue(unsigned int userIndex, int deviceType, int valueKind)
{
// 电池信息由手柄或耳机自身上报;有线设备可能返回无电池或不支持。
HMODULE module = XboxInput_Module();
if (module == NULL) return 1167;
XboxInputGetBatteryInformationProc getBattery =
reinterpret_cast<XboxInputGetBatteryInformationProc>(
GetProcAddress(module, "XInputGetBatteryInformation"));
if (getBattery == NULL) return 127;
XboxInputBatteryInformation battery = {};
unsigned long result = getBattery(userIndex,
static_cast<unsigned char>(deviceType), &battery);
if (result != 0) return static_cast<int>(result);
return valueKind == 0 ? battery.batteryType : battery.batteryLevel;
}
int XboxInput_GetKeystrokeValue(unsigned int userIndex, int reserved, int valueKind)
{
// XInput按键事件是轮询接口,不是Windows消息事件回调。
HMODULE module = XboxInput_Module();
if (module == NULL) return 1167;
XboxInputGetKeystrokeProc getKeystroke =
reinterpret_cast<XboxInputGetKeystrokeProc>(
GetProcAddress(module, "XInputGetKeystroke"));
if (getKeystroke == NULL) return 127;
XboxInputKeystroke key = {};
unsigned long result = getKeystroke(userIndex, reserved, &key);
if (result != 0) return static_cast<int>(result);
switch (valueKind) {
case 0: return key.virtualKey;
case 1: return key.unicode;
case 2: return static_cast<int>(key.flags);
case 3: return key.userIndex;
case 4: return key.hidCode;
default: return 87;
}
}
int XboxInput_Enable(int enable)
{
// 只切换XInput输入处理开关,不能软件配对、连接或断开手柄。
HMODULE module = XboxInput_Module();
if (module == NULL) return 1167;
XboxInputEnableProc enableProc =
reinterpret_cast<XboxInputEnableProc>(
GetProcAddress(module, "XInputEnable"));
if (enableProc == NULL) return 127;
enableProc(enable != 0);
return 0;
}
const wchar_t* XboxInput_GetAudioDeviceGuid(unsigned int userIndex, int renderDevice)
{
// DirectSound GUID导出在部分xinput1_4.dll中不存在,因此尝试1.3回退。
static wchar_t renderGuid;
static wchar_t captureGuid;
GUID renderValue = {};
GUID captureValue = {};
renderGuid = L'\0';
captureGuid = L'\0';
HMODULE module = XboxInput_Module();
XboxInputGetAudioGuidsProc getGuids = NULL;
if (module != NULL)
getGuids = reinterpret_cast<XboxInputGetAudioGuidsProc>(
GetProcAddress(module, "XInputGetDSoundAudioDeviceGuids"));
if (getGuids == NULL) {
module = XboxInput_LegacyModule();
if (module != NULL)
getGuids = reinterpret_cast<XboxInputGetAudioGuidsProc>(
GetProcAddress(module, "XInputGetDSoundAudioDeviceGuids"));
}
if (getGuids == NULL) return L"";
if (getGuids(userIndex, &renderValue, &captureValue) != 0)
return L"";
if (StringFromGUID2(renderValue, renderGuid, 128) == 0 ||
StringFromGUID2(captureValue, captureGuid, 128) == 0)
return L"";
return renderDevice != 0 ? renderGuid : captureGuid;
}
const wchar_t* XboxInput_GetAudioDeviceId(unsigned int userIndex, int renderDevice)
{
// 先查询所需字符数,再动态分配缓冲区,避免固定长度导致设备ID截断。
static std::vector<wchar_t> renderId;
static std::vector<wchar_t> captureId;
unsigned int renderSize = 0;
unsigned int captureSize = 0;
HMODULE module = XboxInput_Module();
if (module == NULL) return L"";
XboxInputGetAudioIdsProc getIds =
reinterpret_cast<XboxInputGetAudioIdsProc>(
GetProcAddress(module, "XInputGetAudioDeviceIds"));
if (getIds == NULL) return L"";
unsigned long result = getIds(
userIndex, NULL, &renderSize, NULL, &captureSize);
if (result != 0)
return L"";
renderId.assign(renderSize == 0 ? 1 : renderSize, L'\0');
captureId.assign(captureSize == 0 ? 1 : captureSize, L'\0');
result = getIds(
userIndex,
renderId.data(), &renderSize,
captureId.data(), &captureSize);
if (result != 0)
return L"";
return renderDevice != 0 ? renderId.data() : captureId.data();
}
xbox_input_wrapper.h#pragma once
#include <windows.h>
// Xbox支持库的C++桥接层。
// 火山层的嵌入式方法调用这里的函数;本文件只暴露稳定的C接口,
// 具体的XInput DLL加载、结构体转换和错误码处理在.cpp中完成。
extern "C" {
// 读取XInput状态字段:0按键,1/2扳机,3到6摇杆,7数据包编号。
int XboxInput_GetValue(unsigned int userIndex, int valueKind);
// 读取能力字段:0类型,1子类型,2标志,3/4左右震动马达能力。
int XboxInput_GetCapabilitiesValue(unsigned int userIndex, unsigned int flags, int valueKind);
// 读取电池字段:0类型,1电量等级。
int XboxInput_GetBatteryValue(unsigned int userIndex, int deviceType, int valueKind);
// 读取按键事件字段:0虚拟键,1 Unicode,2标志,3用户编号,4 HID码。
int XboxInput_GetKeystrokeValue(unsigned int userIndex, int reserved, int valueKind);
// 启用或禁用XInput输入处理;不会连接或断开物理手柄。
int XboxInput_Enable(int enable);
// 获取XInput关联的音频设备标识;不支持时返回空文本。
const wchar_t* XboxInput_GetAudioDeviceGuid(unsigned int userIndex, int renderDevice);
const wchar_t* XboxInput_GetAudioDeviceId(unsigned int userIndex, int renderDevice);
// 设置左右震动马达,强度范围为0到65535。
int XboxInput_SetVibration(
unsigned int userIndex,
unsigned short leftMotor,
unsigned short rightMotor);
// 应用层逻辑按键映射,不会修改手柄硬件按键布局。
int XboxInput_SetButtonMapping(
unsigned short sourceButton,
unsigned short targetButton);
int XboxInput_ClearButtonMapping(unsigned short sourceButton);
void XboxInput_ResetButtonMappings();
unsigned int XboxInput_ApplyButtonMappings(unsigned int buttons);
}
顶, 顶顶顶顶顶顶 本帖最后由 9999 于 2026-9-10 01:26 编辑
错了。
@嵌入式方法不能和 @禁止流程检查一起用。
前者不需要加return且结尾不用带;分号。
@禁止流程检查:本质上就是一个函数,只是不检查返回流程,例如return或者返回。
<火山程序 类型 = "通常" 版本 = 1 />
方法 取能力字段 <公开 静态 类型 = 整数 @禁止流程检查 = 真>
参数 用户编号 <类型 = 整数>
参数 cha询标志 <类型 = 整数>
参数 字段 <类型 = 整数>
{
@ return XboxInput_GetCapabilitiesValue((unsigned int)@<用户编号>, (unsigned int)@<cha询标志>, (int)@<字段>);
}
方法 取能力字段 <公开 静态 类型 = 整数 @嵌入式方法 = "" >
参数 用户编号 <类型 = 整数>
参数 cha询标志 <类型 = 整数>
参数 字段 <类型 = 整数>
{
@ XboxInput_GetCapabilitiesValue((unsigned int)@<用户编号>, (unsigned int)@<cha询标志>, (int)@<字段>)
}
这个库是做哪方面应用的,游戏手柄吗
页:
[1]