随笔 - 70, 文章 - 0, 评论 - 142, 阅读 - 17万
  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理
< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5

PSP开发--[C++]接收按键控制

Posted on   淡如水wp  阅读(868)  评论(0编辑  收藏  举报

 

padctrl.cpp

复制代码
#include <pspkernel.h>
#include
<pspdebug.h>
#include
<pspdisplay.h>
#include
<pspctrl.h>

#include
<iostream>

PSP_MODULE_INFO(
"Hello World", 0, 1, 1);

#define printf pspDebugScreenPrintf

using namespace std;

/* Exit callback */
int exit_callback(int arg1, int arg2, void *common) {
sceKernelExitGame();
return 0;
}

/* Callback thread */
int CallbackThread(SceSize args, void *argp) {
int cbid;
//Create callback
cbid = sceKernelCreateCallback("Exit Callback", exit_callback, NULL);
sceKernelRegisterExitCallback(cbid);

//Sleep thread but service any callbacks as necessary.
sceKernelSleepThreadCB();

return 0;
}

/* Sets up the callback thread and returns its thread id */
int SetupCallbacks() {
int thid = 0;

//Create a thread.
thid = sceKernelCreateThread("update_thread", CallbackThread, 0x11, 0xFA0, 0, 0);
if(thid >= 0) {
//Start a created thread.
sceKernelStartThread(thid, 0, 0);
}

return thid;
}

int main(int argc, char **argv)
{
//Initialise the debug screen.
pspDebugScreenInit();
//setup callback;
SetupCallbacks();

//按键struct
SceCtrlData pad;

printf(
"Press [X] To Start the Timer");

while(1)
{
//Read buffer positive.
sceCtrlReadBufferPositive(&pad, 1);

if(pad.Buttons & PSP_CTRL_CROSS)
{
printf(
"you pressed X");
break;
}
//清屏
pspDebugScreenClear();
}

//Sleep thread
sceKernelSleepThread();

return 0;
}
复制代码

makefile

复制代码
TARGET = padctrl
OBJS
= padctrl.o

BUILD_PRX
= 1
PSP_FW_VERSION
= 371

# C编译器参数
CFLAGS
= -O2 -G0 -Wall
# C++编译器参数
CXXFLAGS
= $(CFLAGS) -fno-exceptions -fno-rtti
# 汇编编译器参数
ASFLAGS
= $(CFLAGS)

# 引用的库 -l stdC++
LIBS
= -lstdc++

EXTRA_TARGETS
= EBOOT.PBP
PSP_EBOOT_TITLE
= pad control

PSPSDK
=$(shell psp-config --pspsdk-path)
include $(PSPSDK)/lib/build.mak




复制代码

 按键的枚举

PSP_CTRL_SELECT  Select button.
PSP_CTRL_START  Start button.
PSP_CTRL_UP  Up D-Pad button.
PSP_CTRL_RIGHT  Right D-Pad button.
PSP_CTRL_DOWN  Down D-Pad button.
PSP_CTRL_LEFT  Left D-Pad button.
PSP_CTRL_LTRIGGER  Left trigger.
PSP_CTRL_RTRIGGER  Right trigger.
PSP_CTRL_TRIANGLE  Triangle button.
PSP_CTRL_CIRCLE  Circle button.
PSP_CTRL_CROSS  Cross button.
PSP_CTRL_SQUARE  Square button.
PSP_CTRL_HOME  Home button.
PSP_CTRL_HOLD  Hold button.
PSP_CTRL_NOTE  Music Note button.

 

接收按键需要一个while(1)来接受系统事件。
然后通过sceCtrlReadBufferPositive(&pad, 1); 来读取按键内容。

编辑推荐:
· 软件产品开发中常见的10个问题及处理方法
· .NET 原生驾驭 AI 新基建实战系列:向量数据库的应用与畅想
· 从问题排查到源码分析:ActiveMQ消费端频繁日志刷屏的秘密
· 一次Java后端服务间歇性响应慢的问题排查记录
· dotnet 源代码生成器分析器入门
阅读排行:
· 软件产品开发中常见的10个问题及处理方法
· 互联网不景气了那就玩玩嵌入式吧,用纯.NET开发并制作一个智能桌面机器人(四):结合BotSharp
· Vite CVE-2025-30208 安全漏洞
· MQ 如何保证数据一致性?
· 《HelloGitHub》第 108 期
点击右上角即可分享
微信分享提示