Game Boy Advance >> C/C++

Input


參考資訊:
1. libnds doc

說明:

API
void scanKeys(void)
u16 keysDown(void)

按鍵:

typedef enum KEYPAD_BITS {
    KEY_A           =   (1 << 0),     /*!< keypad A button */
    KEY_B           =   (1 << 1),     /*!< keypad B button */
    KEY_SELECT      =   (1 << 2),     /*!< keypad SELECT button */
    KEY_START       =   (1 << 3),     /*!< keypad START button */
    KEY_RIGHT       =   (1 << 4),     /*!< dpad RIGHT */
    KEY_LEFT        =   (1 << 5),     /*!< dpad LEFT */
    KEY_UP          =   (1 << 6),     /*!< dpad UP */
    KEY_DOWN        =   (1 << 7),     /*!< dpad DOWN */
    KEY_R           =   (1 << 8),     /*!< Right shoulder button */
    KEY_L           =   (1 << 9),     /*!< Left shoulder button */

    KEYIRQ_ENABLE   =   (1 << 14),    /*!< Enable keypad interrupt */
    KEYIRQ_OR       =   (0 << 15),    /*!< interrupt logical OR mode */
    KEYIRQ_AND      =   (1 << 15),    /*!< interrupt logical AND mode */
    DPAD            =   (KEY_UP | KEY_DOWN | KEY_LEFT | KEY_RIGHT) /*!< mask all dpad buttons */
} KEYPAD_BITS;

main.c

#include <stdio.h>
#include <gba_console.h>
#include <gba_input.h>
 
int main(void)
{
    u16 key = 0;

    consoleDemoInit();
    while (1) {
        scanKeys();
        key = keysDown();
        if (key) {
            iprintf(CON_CLS());
            printf("0x%x\n", key);
        }
    }
    return 0;
}

完成


返回上一頁