reman3/Rayman_X/cpa/public/INO/Keyboard.h

449 lines
16 KiB
C

/*
Keyboard.h : Functions definition for the keyboard management.
Author : JENTEY F.
Last update : 03/07/96
01/08/97 Direct Input
*/
#ifndef _INO_KEYBOARD_H
#define _INO_KEYBOARD_H
#include "cpa_std.h"
#include "dinput.h"
#ifndef u_short
#define u_short unsigned short
#endif
#ifndef u_long
#define u_long unsigned long
#endif
/**************************************/
#ifndef CPA_EXPORT
#if defined(CPA_WANTS_IMPORT)
#define CPA_EXPORT __declspec(dllimport)
#elif defined(CPA_WANTS_EXPORT)
#define CPA_EXPORT __declspec(dllexport)
#else
#define CPA_EXPORT
#endif
#endif
/**************************************/
/* All functions return a short value that should be compared with this constant */
#define C_wKbError 32767
#define C_wKbTrue 32766
#define C_wKbFalse 32765
/* Keyboard error code */
#define C_FirstErrorKeyboard 0x2000
#define C_ErrKeyboardNotInitialized ( C_FirstErrorKeyboard + 0 )
#define C_ErrBadKeyCode ( C_FirstErrorKeyboard + 1 )
#define C_ErrNotInRecordingMode ( C_FirstErrorKeyboard + 2 )
#define C_ErrNotInNormalMode ( C_FirstErrorKeyboard + 3 )
#define C_ErrNotInPlayingMode ( C_FirstErrorKeyboard + 4 )
#define C_ErrDemoBadFileFormat ( C_FirstErrorKeyboard + 5 )
#define C_ErrDemoFileError ( C_FirstErrorKeyboard + 6 )
#define C_ErrHistoricOverflow ( C_FirstErrorKeyboard + 7 )
#define C_ErrFocusLost ( C_FirstErrorKeyboard + 8 )
#define C_ErrDirectInputError ( C_FirstErrorKeyboard + 9 )
/* Key state */
#define C_ucKeyPressed 0x80
/* Constant to use to select key */
#define C_ucKey_SQUARE DIK_GRAVE
#define C_ucKey_1 DIK_1
#define C_ucKey_2 DIK_2
#define C_ucKey_3 DIK_3
#define C_ucKey_4 DIK_4
#define C_ucKey_5 DIK_5
#define C_ucKey_6 DIK_6
#define C_ucKey_7 DIK_7
#define C_ucKey_8 DIK_8
#define C_ucKey_9 DIK_9
#define C_ucKey_0 DIK_0
#define C_ucKey_END_BRACET DIK_MINUS
#define C_ucKey_EQUAL DIK_EQUALS
#define C_ucKey_A DIK_Q
#define C_ucKey_Z DIK_W
#define C_ucKey_E DIK_E
#define C_ucKey_R DIK_R
#define C_ucKey_T DIK_T
#define C_ucKey_Y DIK_Y
#define C_ucKey_U DIK_U
#define C_ucKey_I DIK_I
#define C_ucKey_O DIK_O
#define C_ucKey_P DIK_P
#define C_ucKey_EXP DIK_LBRACKET
#define C_ucKey_DOLLAR DIK_RBRACKET
#define C_ucKey_Q DIK_A
#define C_ucKey_S DIK_S
#define C_ucKey_D DIK_D
#define C_ucKey_F DIK_F
#define C_ucKey_G DIK_G
#define C_ucKey_H DIK_H
#define C_ucKey_J DIK_J
#define C_ucKey_K DIK_K
#define C_ucKey_L DIK_L
#define C_ucKey_M DIK_SEMICOLON
#define C_ucKey_PERCENT DIK_APOSTROPHE
#define C_ucKey_MUL DIK_BACKSLASH
#define C_ucKey_INF 0x56 /* Not define in dinput.h */
#define C_ucKey_W DIK_Z
#define C_ucKey_X DIK_X
#define C_ucKey_C DIK_C
#define C_ucKey_V DIK_V
#define C_ucKey_B DIK_B
#define C_ucKey_N DIK_N
#define C_ucKey_VIRG DIK_M
#define C_ucKey_PVIRG DIK_COMMA
#define C_ucKey_PP DIK_PERIOD
#define C_ucKey_NOT DIK_SLASH
#define C_ucKey_F1 DIK_F1
#define C_ucKey_F2 DIK_F2
#define C_ucKey_F3 DIK_F3
#define C_ucKey_F4 DIK_F4
#define C_ucKey_F5 DIK_F5
#define C_ucKey_F6 DIK_F6
#define C_ucKey_F7 DIK_F7
#define C_ucKey_F8 DIK_F8
#define C_ucKey_F9 DIK_F9
#define C_ucKey_F10 DIK_F10
#define C_ucKey_F11 DIK_F11
#define C_ucKey_F12 DIK_F12
#define C_ucKey_SYSTEM DIK_SYSRQ
#define C_ucKey_SCROLL DIK_SCROLL
#define C_ucKey_PAUSE 0x69 /* Not define in dinput.h*/
#define C_ucKey_SPACE DIK_SPACE
#define C_ucKey_ESC DIK_ESCAPE
#define C_ucKey_TAB DIK_TAB
#define C_ucKey_CAPSLOCK DIK_CAPITAL
#define C_ucKey_LSHIFT DIK_LSHIFT
#define C_ucKey_RSHIFT DIK_RSHIFT
#define C_ucKey_RCTRL DIK_RCONTROL
#define C_ucKey_LCTRL DIK_LCONTROL
#define C_ucKey_LALT DIK_LMENU
#define C_ucKey_RALT DIK_RMENU
#define C_ucKey_ALTGR DIK_LCONTROL
#define C_ucKey_ENTER DIK_RETURN
#define C_ucKey_BACK DIK_BACK
#define C_ucKey_INS DIK_INSERT
#define C_ucKey_DEL DIK_DELETE
#define C_ucKey_HOME DIK_HOME
#define C_ucKey_END DIK_END
#define C_ucKey_PRIOR DIK_PRIOR
#define C_ucKey_NEXT DIK_NEXT
#define C_ucKey_UP DIK_UP
#define C_ucKey_DOWN DIK_DOWN
#define C_ucKey_LEFT DIK_LEFT
#define C_ucKey_RIGHT DIK_RIGHT
#define C_ucKey_PAD_ENTER DIK_NUMPADENTER
#define C_ucKey_NUMLOCK 0xc5 /* DIK_NUMLOCK ?? */
#define C_ucKey_PAD_DIV DIK_DIVIDE
#define C_ucKey_PAD_MUL DIK_MULTIPLY
#define C_ucKey_PAD_SUB DIK_SUBTRACT
#define C_ucKey_PAD_ADD DIK_ADD
#define C_ucKey_PAD_POINT DIK_DECIMAL
#define C_ucKey_PAD_0 DIK_NUMPAD0
#define C_ucKey_PAD_1 DIK_NUMPAD1
#define C_ucKey_PAD_2 DIK_NUMPAD2
#define C_ucKey_PAD_3 DIK_NUMPAD3
#define C_ucKey_PAD_4 DIK_NUMPAD4
#define C_ucKey_PAD_5 DIK_NUMPAD5
#define C_ucKey_PAD_6 DIK_NUMPAD6
#define C_ucKey_PAD_7 DIK_NUMPAD7
#define C_ucKey_PAD_8 DIK_NUMPAD8
#define C_ucKey_PAD_9 DIK_NUMPAD9
#define C_ucKey_LWIN DIK_LWIN
#define C_ucKey_RWIN DIK_RWIN
#define C_ucKey_APPS DIK_APPS
/******************************************************************************
All functions return a short type value that must be compared with the
C_wKbError to check if the function success. You can then read the error
code with the error management functions.
******************************************************************************/
#if !defined U64
/*////////////////////*/
/* Global Variables //*/
/*////////////////////*/
#undef EXTERN
#undef extern
#if !defined(__DeclareGlobalVariableIntell_h__)
#define EXTERN extern
#else
#define EXTERN
#endif /* __DeclareGlobalVariableIntell_h__*/
EXTERN char g_cIsAzerty;
#endif /* U64*/
#if defined(__cplusplus)
extern "C"
{
/******************************************************************************
Keyboard initialisation functions.
******************************************************************************/
/*
This function must be called one time when the game is launched. The
parameter HistorySize is the number of previous status conserve.
*/
CPA_EXPORT short INO_fn_wInitKeyboard(short wHistorySize, HINSTANCE hInstance, HWND hWindow);
/*
Reinitialization of the keyboard. The history is clear.
*/
CPA_EXPORT short INO_fn_wResetKeyboard(void);
/*
This function free memory and release keyboard ressource.
*/
CPA_EXPORT short INO_fn_wFreeKeyboard(void);
/*
This function returns the number of keys of the keyboard.
*/
CPA_EXPORT short INO_fn_wGetNumberOfKey(void);
/******************************************************************************
Keyboard state.
******************************************************************************/
/*
This function must be called at regular interval, for example each VBL.
It Update the informations about the keyboard.
*/
CPA_EXPORT short INO_fn_wReadKeyboard(void);
/*
Retrun C_wKbTrue if the application has the keyboard focus
*/
CPA_EXPORT short INO_fn_wIsKeyboardAcquired(void);
/*
Remove an active key. An error occurs when the specified key isn't
active.
*/
CPA_EXPORT short INO_fn_wRemoveActiveKey(short wKeyCode);
/*
Add a key to be managed. There is an error if the specified key is
already active.
*/
CPA_EXPORT short INO_fn_wAddActiveKey(short wKeyCode);
/*
Return the code of the last pressed key.
*/
CPA_EXPORT short INO_fn_wGetLastKey(void);
/*
This function return c_wKbTrue if the keyboard state has changed since
the last
*/
CPA_EXPORT short INO_fn_wKeyboardStateHasChanged(void);
/*
This function returns C_wKbTrue if the specified key is down else the result
is C_wKbFalse.
*/
CPA_EXPORT short INO_fn_wKeyDown(short wKeyCode);
/*
This function returns C_wKbTrue if the specified key has just been pressed.
( it wasn't pressed after the previous call of fn_wKbReadKeyboard and it is
pressed after the last call of this fonction).
*/
CPA_EXPORT short INO_fn_wKeyJustDown(short wKeyCode);
/*
This function returns C_wKbTrue if the specified key has just been released.
( it was pressed after the previous call of fn_wKbReadKeyboard and it isn't
yet).
*/
CPA_EXPORT short INO_fn_wKeyJustUp(short wKeyCode);
/*
This function return C_wKbTrue if the selected key was down in the
specified previous state.
*/
CPA_EXPORT short INO_fn_wKeyWasDown(short wKeycode, short wHistoryIndex);
/*
This fonction returns the ASCII code corresponding to a key code if this key
is printable.
*/
/*
CPA_EXPORT short INO_fn_wGetASCIICodeOfKey(short wKeyCode);
*/
/*
This fonction returns the ASCII code corresponding to the keyboard current state.
If the last pressed key is not printable, return an error.
*/
CPA_EXPORT short INO_fn_wGetLastASCIICode(void);
/*
This function compares the string pointed by the p_szTestString with the
string formed with the last pressed key.
*/
CPA_EXPORT short INO_fn_wCompareWithCurrentString(char *p_szTestString);
/*
If not C_wJoyError, the result is the elapsed time of inactivity
of the keyboard.
*/
CPA_EXPORT short INO_fn_wGetKeyboardInactivityTime(u_long *p_ulCount);
/*
If not C_wJoyError, the result is the elapsed time since the
specified previous state.
*/
CPA_EXPORT short INO_fn_wKbElapsedTime(short wHistoryIndex, u_long *p_ulCount);
/*
This function returns a pointer to the last error message string.
*/
CPA_EXPORT short INO_fn_wGetErrorString(char **pp_szErrorString);
/*
This function returns a last error code.
*/
CPA_EXPORT u_long INO_fn_ulGetLastErrorCode(void);
/*********************************************************************
Demo mode functions
*********************************************************************/
/*
DEFINE THE KEYS TO STOP THE DEMO RECORDING MODE.
OF COURSE, THE DEFINE HERE SHOULDN'T BE USED IN THE GAME.
DEFAULT IS ESC.
*/
CPA_EXPORT short INO_fn_wAddStopRecordingKey(short wKeyCode);
/*
REMOVE A KEY FROM THE EXIT DEMO KEY LIST.
*/
CPA_EXPORT short INO_fn_wRemoveStopRecordingKey(short wKeyCode);
/*
STARTS THE DEMO RECORDING MODE. A FILE IS CREATE WITH THE NAME INDICATED BY
p_szFileName.
*/
CPA_EXPORT short INO_fn_wStartRecordingKeyboard(char *p_szFileName);
/*
Quit the demo recording mode. The data of the demo sequence are stored in the file
open in the fn_wKbStartDemoRecordMode.
*/
CPA_EXPORT short INO_fn_wStopRecordingKeyboard(void);
/*
THIS FUNCTION RETURN THE NUMBER OF FRAME OF THE DEMO SEQUENCE.
*/
CPA_EXPORT short INO_fn_wGetKeyboardDemoFrameCount(void);
/*
THIS FUNCTION START THE DEMO PLAYING MODE.
*/
CPA_EXPORT short INO_fn_wStartKeyboardDemo(char *p_szFileName);
/*
THIS FUNCTION QUIT THE DEMO PLAYING MODE.
*/
CPA_EXPORT short INO_fn_wStopKeyboardDemo(void);
/*
THIS FUNCTION RETURN THE CURRENT KEYBOARD MODE.(NORMAL, DEMO RECORDING
OR DEMO PLAYING).
*/
CPA_EXPORT short INO_fn_wGetKeyboardCurrentMode(void);
}
#else /* C prototype */
extern CPA_EXPORT short INO_fn_wInitKeyboard(short wHistorySize, HINSTANCE hInstance, HWND hWindow);
extern CPA_EXPORT short INO_fn_wResetKeyboard(void);
extern CPA_EXPORT short INO_fn_wFreeKeyboard(void);
extern CPA_EXPORT short INO_fn_wGetNumberOfKey(void);
extern CPA_EXPORT short INO_fn_wReadKeyboard(void);
extern CPA_EXPORT short INO_fn_wIsKeyboardAcquired(void);
extern CPA_EXPORT short INO_fn_wRemoveActiveKey(short wKeyCode);
extern CPA_EXPORT short INO_fn_wAddActiveKey(short wKeyCode);
extern CPA_EXPORT short INO_fn_wGetLastKey(void);
extern CPA_EXPORT short INO_fn_wKeyboardStateHasChanged(void);
extern CPA_EXPORT short INO_fn_wKeyDown(short wKeyCode);
extern CPA_EXPORT short INO_fn_wKeyJustDown(short wKeyCode);
extern CPA_EXPORT short INO_fn_wKeyJustUp(short wKeyCode);
extern CPA_EXPORT short INO_fn_wKeyWasDown(short wKeycode, short wHistoryIndex);
/*CPA_EXPORT short INO_fn_wGetASCIICodeOfKey(short wKeyCode);*/
extern CPA_EXPORT short INO_fn_wGetLastASCIICode(void);
extern CPA_EXPORT short INO_fn_wCompareWithCurrentString(char *p_szTestString);
extern CPA_EXPORT short INO_fn_wGetKeyboardInactivityTime(u_long *p_ulCount);
extern CPA_EXPORT short INO_fn_wKbElapsedTime(short wHistoryIndex, u_long *p_ulCount);
extern CPA_EXPORT short INO_fn_wGetErrorString(char **pp_szErrorString);
extern CPA_EXPORT u_long INO_fn_ulGetLastErrorCode(void);
extern CPA_EXPORT short INO_fn_wAddStopRecordingKey(short wKeyCode);
extern CPA_EXPORT short INO_fn_wRemoveStopRecordingKey(short wKeyCode);
extern CPA_EXPORT short INO_fn_wStartRecordingKeyboard(char *p_szFileName);
extern CPA_EXPORT short INO_fn_wStopRecordingKeyboard(void);
extern CPA_EXPORT short INO_fn_wGetKeyboardDemoFrameCount(void);
extern CPA_EXPORT short INO_fn_wStartKeyboardDemo(char *p_szFileName);
extern CPA_EXPORT short INO_fn_wStopKeyboardDemo(void);
extern CPA_EXPORT short INO_fn_wGetKeyboardCurrentMode(void);
#endif
/* Old prototype compatibility */
#define fn_wKbInitKeyboard(A,B,C) INO_fn_wInitKeyboard(A,B,C)
#define fn_wKbResetKeyboard() INO_fn_wResetKeyboard()
#define fn_wKbFreeKeyboard() INO_fn_wFreeKeyboard()
#define fn_wKbKeyNumber() INO_fn_wGetNumberOfKey()
#define fn_wKbReadKeyboard() INO_fn_wReadKeyboard()
#define fn_wKbIsKeyboardAcquired() INO_fn_wIsKeyboardAcquired()
#define fn_wKbRemoveActiveKey(A) INO_fn_wRemoveActiveKey(A)
#define fn_wKbAddActiveKey(A) INO_fn_wAddActiveKey(A)
#define fn_wKbLastKey() INO_fn_wGetLastKey()
#define fn_wKbStateHasChanged() INO_fn_wKeyboardStateHasChanged()
#define fn_wKbIsDown(A) INO_fn_wKeyDown(A)
#define fn_wKbJustDown(A) INO_fn_wKeyJustDown(A)
#define fn_wKbJustUp(A) INO_fn_wKeyJustUp(A)
#define fn_wKbWasDown(A,B) INO_fn_wKeyWasDown(A,B)
#define fn_wKbGetLastASCII() INO_fn_wGetCurrentASCIICode()
#define fn_wKbCompareString(A) INO_fn_wCompareWithCurrentString(A)
#define fn_wKbInactivityTime(A) INO_fn_wGetKeyboardInactivityTime(A)
#define fn_wKbElapsedTime(A,B) INO_fn_wKbElapsedTime(A,B)
#define fn_wKbAddExitDemoKey(A) INO_fn_wAddStopRecordingKey(A)
#define fn_wKbRemoveExitDemoKey(A) INO_fn_wRemoveStopRecordingKey(A)
#define fn_wKbStartDemoRecording(A) INO_fn_wStartRecordingKeyboard(A)
#define fn_wKbExitDemoRecording() INO_fn_wStopRecordingKeyboard()
#define fn_wKbGetDemoFrameCount() INO_fn_wGetKeyboardDemoFrameCount()
#define fn_wKbStartDemoPlaying(A) INO_fn_wStartKeyboardDemo(A)
#define fn_wKbExitDemoPlaying() INO_fn_wStopKeyboardDemo()
#define fn_wKbGetCurrentMode() INO_fn_wGetKeyboardCurrentMode()
#define fn_wKbGetErrorString(A) INO_fn_wGetErrorString(A)
#define fn_ulKbGetLastErrorCode() INO_fn_ulGetLastErrorCode()
#endif /* _INO_KEYBOARD_H */