博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
PSP开发--[C++]接收按键控制
阅读量:2506 次
发布时间:2019-05-11

本文共 3908 字,大约阅读时间需要 13 分钟。

 

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); 来读取按键内容。

转载地址:http://falgb.baihongyu.com/

你可能感兴趣的文章
FTP站点建立 普通电脑版&&服务器版
查看>>
js 给一段代码,给出运行后的最终结果的一些综合情况、
查看>>
webservice 详解
查看>>
js自动补全实例
查看>>
VS无法启动调试:“生成下面的模块时,启用了优化或没有调试信息“
查看>>
npm 安装 sass=-=-=
查看>>
WINFORM中加入WPF控件并绑定数据源实现跨线程自动更新
查看>>
C#类对象的事件定义
查看>>
各类程序员学习路线图
查看>>
HDU 5510 Bazinga KMP
查看>>
关于select @@IDENTITY的初识
查看>>
ASP.NET MVC ajax提交 防止CSRF攻击
查看>>
关于CSS伪类选择器
查看>>
适用于带文字 和图片的垂直居中方法
查看>>
Part 2 - Fundamentals(4-10)
查看>>
使用Postmark测试后端存储性能
查看>>
NSTextView 文字链接的定制化
查看>>
第五天站立会议内容
查看>>
CentOs7安装rabbitmq
查看>>
(转))iOS App上架AppStore 会遇到的坑
查看>>