Added GameKeys.EventToCharacter(event, is_shift) so you can get the character that would be types when pressing a key.
Last commit was made in the pydocs folder only, so this includes changes mentioned in rev 19620.
This commit is contained in:
@@ -129,7 +129,14 @@ static inline void Py_Fatal(const char *M) {
|
||||
\
|
||||
if(descr) { \
|
||||
if (PyCObject_Check(descr)) { \
|
||||
return py_set_attrdef((void *)this, (const PyAttributeDef*)PyCObject_AsVoidPtr(descr), value); \
|
||||
const PyAttributeDef* attrdef= reinterpret_cast<const PyAttributeDef *>(PyCObject_AsVoidPtr(descr)); \
|
||||
if (attrdef->m_access == KX_PYATTRIBUTE_RO) { \
|
||||
PyErr_Format(PyExc_AttributeError, "\"%s\" is read only", PyString_AsString(attr)); \
|
||||
return -1; \
|
||||
} \
|
||||
else { \
|
||||
return py_set_attrdef((void *)this, attrdef, value); \
|
||||
} \
|
||||
} else { \
|
||||
PyErr_Format(PyExc_AttributeError, "\"%s\" cannot be set", PyString_AsString(attr)); \
|
||||
return -1; \
|
||||
|
||||
@@ -352,151 +352,7 @@ void SCA_KeyboardSensor::AddToTargetProp(int keyIndex)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether this character can be printed. We cannot use
|
||||
* the library functions here, because we need to test our own
|
||||
* keycodes. */
|
||||
bool SCA_KeyboardSensor::IsPrintable(int keyIndex)
|
||||
{
|
||||
/* only print
|
||||
* - numerals: KX_ZEROKEY to KX_NINEKEY
|
||||
* - alphas: KX_AKEY to KX_ZKEY.
|
||||
* - specials: KX_RETKEY, KX_PADASTERKEY, KX_PADCOMMAKEY to KX_PERIODKEY,
|
||||
* KX_TABKEY , KX_SEMICOLONKEY to KX_RIGHTBRACKETKEY,
|
||||
* KX_PAD2 to KX_PADPLUSKEY
|
||||
* - delete and backspace: also printable in the sense that they modify
|
||||
* the string
|
||||
* - retkey: should this be printable?
|
||||
* - virgule: prints a space... don't know which key that's supposed
|
||||
* to be...
|
||||
*/
|
||||
if ( ((keyIndex >= SCA_IInputDevice::KX_ZEROKEY)
|
||||
&& (keyIndex <= SCA_IInputDevice::KX_NINEKEY))
|
||||
|| ((keyIndex >= SCA_IInputDevice::KX_AKEY)
|
||||
&& (keyIndex <= SCA_IInputDevice::KX_ZKEY))
|
||||
|| (keyIndex == SCA_IInputDevice::KX_SPACEKEY)
|
||||
|| (keyIndex == SCA_IInputDevice::KX_RETKEY)
|
||||
|| (keyIndex == SCA_IInputDevice::KX_PADENTER)
|
||||
|| (keyIndex == SCA_IInputDevice::KX_PADASTERKEY)
|
||||
|| (keyIndex == SCA_IInputDevice::KX_TABKEY)
|
||||
|| ((keyIndex >= SCA_IInputDevice::KX_COMMAKEY)
|
||||
&& (keyIndex <= SCA_IInputDevice::KX_PERIODKEY))
|
||||
|| ((keyIndex >= SCA_IInputDevice::KX_SEMICOLONKEY)
|
||||
&& (keyIndex <= SCA_IInputDevice::KX_RIGHTBRACKETKEY))
|
||||
|| ((keyIndex >= SCA_IInputDevice::KX_PAD2)
|
||||
&& (keyIndex <= SCA_IInputDevice::KX_PADPLUSKEY))
|
||||
|| (keyIndex == SCA_IInputDevice::KX_DELKEY)
|
||||
|| (keyIndex == SCA_IInputDevice::KX_BACKSPACEKEY)
|
||||
)
|
||||
{
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// this code looks ugly, please use an ordinary hashtable
|
||||
|
||||
char SCA_KeyboardSensor::ToCharacter(int keyIndex, bool shifted)
|
||||
{
|
||||
/* numerals */
|
||||
if ( (keyIndex >= SCA_IInputDevice::KX_ZEROKEY)
|
||||
&& (keyIndex <= SCA_IInputDevice::KX_NINEKEY) ) {
|
||||
if (shifted) {
|
||||
char numshift[] = ")!@#$%^&*(";
|
||||
return numshift[keyIndex - '0'];
|
||||
} else {
|
||||
return keyIndex - SCA_IInputDevice::KX_ZEROKEY + '0';
|
||||
}
|
||||
}
|
||||
|
||||
/* letters... always lowercase... is that desirable? */
|
||||
if ( (keyIndex >= SCA_IInputDevice::KX_AKEY)
|
||||
&& (keyIndex <= SCA_IInputDevice::KX_ZKEY) ) {
|
||||
if (shifted) {
|
||||
return keyIndex - SCA_IInputDevice::KX_AKEY + 'A';
|
||||
} else {
|
||||
return keyIndex - SCA_IInputDevice::KX_AKEY + 'a';
|
||||
}
|
||||
}
|
||||
|
||||
if (keyIndex == SCA_IInputDevice::KX_SPACEKEY) {
|
||||
return ' ';
|
||||
}
|
||||
if (keyIndex == SCA_IInputDevice::KX_RETKEY || keyIndex == SCA_IInputDevice::KX_PADENTER) {
|
||||
return '\n';
|
||||
}
|
||||
|
||||
|
||||
if (keyIndex == SCA_IInputDevice::KX_PADASTERKEY) {
|
||||
return '*';
|
||||
}
|
||||
|
||||
if (keyIndex == SCA_IInputDevice::KX_TABKEY) {
|
||||
return '\t';
|
||||
}
|
||||
|
||||
/* comma to period */
|
||||
char commatoperiod[] = ",-.";
|
||||
char commatoperiodshifted[] = "<_>";
|
||||
if (keyIndex == SCA_IInputDevice::KX_COMMAKEY) {
|
||||
if (shifted) {
|
||||
return commatoperiodshifted[0];
|
||||
} else {
|
||||
return commatoperiod[0];
|
||||
}
|
||||
}
|
||||
if (keyIndex == SCA_IInputDevice::KX_MINUSKEY) {
|
||||
if (shifted) {
|
||||
return commatoperiodshifted[1];
|
||||
} else {
|
||||
return commatoperiod[1];
|
||||
}
|
||||
}
|
||||
if (keyIndex == SCA_IInputDevice::KX_PERIODKEY) {
|
||||
if (shifted) {
|
||||
return commatoperiodshifted[2];
|
||||
} else {
|
||||
return commatoperiod[2];
|
||||
}
|
||||
}
|
||||
|
||||
/* semicolon to rightbracket */
|
||||
char semicolontorightbracket[] = ";\'`/\\=[]";
|
||||
char semicolontorightbracketshifted[] = ":\"~\?|+{}";
|
||||
if ((keyIndex >= SCA_IInputDevice::KX_SEMICOLONKEY)
|
||||
&& (keyIndex <= SCA_IInputDevice::KX_RIGHTBRACKETKEY)) {
|
||||
if (shifted) {
|
||||
return semicolontorightbracketshifted[keyIndex - SCA_IInputDevice::KX_SEMICOLONKEY];
|
||||
} else {
|
||||
return semicolontorightbracket[keyIndex - SCA_IInputDevice::KX_SEMICOLONKEY];
|
||||
}
|
||||
}
|
||||
|
||||
/* keypad2 to padplus */
|
||||
char pad2topadplus[] = "246813579. 0- +";
|
||||
if ((keyIndex >= SCA_IInputDevice::KX_PAD2)
|
||||
&& (keyIndex <= SCA_IInputDevice::KX_PADPLUSKEY)) {
|
||||
return pad2topadplus[keyIndex - SCA_IInputDevice::KX_PAD2];
|
||||
}
|
||||
|
||||
return '!';
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests whether this is a delete key.
|
||||
*/
|
||||
bool SCA_KeyboardSensor::IsDelete(int keyIndex)
|
||||
{
|
||||
if ( (keyIndex == SCA_IInputDevice::KX_DELKEY)
|
||||
|| (keyIndex == SCA_IInputDevice::KX_BACKSPACEKEY) ) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests whether shift is pressed
|
||||
*/
|
||||
@@ -654,7 +510,7 @@ const char SCA_KeyboardSensor::GetPressedKeys_doc[] =
|
||||
|
||||
PyObject* SCA_KeyboardSensor::PyGetPressedKeys(PyObject* self, PyObject* args, PyObject* kwds)
|
||||
{
|
||||
ShowDeprecationWarning("getPressedKeys()", "getEventList()");
|
||||
ShowDeprecationWarning("getPressedKeys()", "events");
|
||||
|
||||
SCA_IInputDevice* inputdev = m_pKeyboardMgr->GetInputDevice();
|
||||
|
||||
@@ -672,20 +528,19 @@ PyObject* SCA_KeyboardSensor::PyGetPressedKeys(PyObject* self, PyObject* args, P
|
||||
if ((inevent.m_status == SCA_InputEvent::KX_JUSTACTIVATED)
|
||||
|| (inevent.m_status == SCA_InputEvent::KX_JUSTRELEASED))
|
||||
{
|
||||
if (index < num)
|
||||
{
|
||||
PyObject* keypair = PyList_New(2);
|
||||
PyList_SetItem(keypair,0,PyInt_FromLong(i));
|
||||
PyList_SetItem(keypair,1,PyInt_FromLong(inevent.m_status));
|
||||
PyList_SetItem(resultlist,index,keypair);
|
||||
index++;
|
||||
}
|
||||
PyObject* keypair = PyList_New(2);
|
||||
PyList_SET_ITEM(keypair,0,PyInt_FromLong(i));
|
||||
PyList_SET_ITEM(keypair,1,PyInt_FromLong(inevent.m_status));
|
||||
PyList_SET_ITEM(resultlist,index,keypair);
|
||||
index++;
|
||||
|
||||
if (index >= num) /* should not happen */
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (index>0) return resultlist;
|
||||
}
|
||||
}
|
||||
|
||||
Py_RETURN_NONE;
|
||||
return resultlist;
|
||||
}
|
||||
|
||||
|
||||
@@ -696,9 +551,9 @@ const char SCA_KeyboardSensor::GetCurrentlyPressedKeys_doc[] =
|
||||
|
||||
PyObject* SCA_KeyboardSensor::PyGetCurrentlyPressedKeys(PyObject* self, PyObject* args, PyObject* kwds)
|
||||
{
|
||||
ShowDeprecationWarning("getCurrentlyPressedKeys()", "getEventList()");
|
||||
ShowDeprecationWarning("getCurrentlyPressedKeys()", "events");
|
||||
|
||||
SCA_IInputDevice* inputdev = m_pKeyboardMgr->GetInputDevice();
|
||||
SCA_IInputDevice* inputdev = m_pKeyboardMgr->GetInputDevice();
|
||||
|
||||
int num = inputdev->GetNumActiveEvents();
|
||||
PyObject* resultlist = PyList_New(num);
|
||||
@@ -713,29 +568,28 @@ SCA_IInputDevice* inputdev = m_pKeyboardMgr->GetInputDevice();
|
||||
if ( (inevent.m_status == SCA_InputEvent::KX_ACTIVE)
|
||||
|| (inevent.m_status == SCA_InputEvent::KX_JUSTACTIVATED))
|
||||
{
|
||||
if (index < num)
|
||||
{
|
||||
PyObject* keypair = PyList_New(2);
|
||||
PyList_SetItem(keypair,0,PyInt_FromLong(i));
|
||||
PyList_SetItem(keypair,1,PyInt_FromLong(inevent.m_status));
|
||||
PyList_SetItem(resultlist,index,keypair);
|
||||
index++;
|
||||
}
|
||||
PyObject* keypair = PyList_New(2);
|
||||
PyList_SET_ITEM(keypair,0,PyInt_FromLong(i));
|
||||
PyList_SET_ITEM(keypair,1,PyInt_FromLong(inevent.m_status));
|
||||
PyList_SET_ITEM(resultlist,index,keypair);
|
||||
index++;
|
||||
|
||||
if (index >= num) /* should never happen */
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/* why?*/
|
||||
if (index > 0) return resultlist;
|
||||
}
|
||||
|
||||
Py_RETURN_NONE;
|
||||
return resultlist;
|
||||
}
|
||||
//<---- Deprecated
|
||||
|
||||
|
||||
KX_PYMETHODDEF_DOC_NOARGS(SCA_KeyboardSensor, getEventList,
|
||||
"getEventList()\n"
|
||||
"\tGet the list of the keyboard events in this frame.\n")
|
||||
{
|
||||
ShowDeprecationWarning("getEventList()", "events");
|
||||
|
||||
SCA_IInputDevice* inputdev = m_pKeyboardMgr->GetInputDevice();
|
||||
|
||||
PyObject* resultlist = PyList_New(0);
|
||||
@@ -746,34 +600,35 @@ KX_PYMETHODDEF_DOC_NOARGS(SCA_KeyboardSensor, getEventList,
|
||||
if (inevent.m_status != SCA_InputEvent::KX_NO_INPUTSTATUS)
|
||||
{
|
||||
PyObject* keypair = PyList_New(2);
|
||||
PyList_SetItem(keypair,0,PyInt_FromLong(i));
|
||||
PyList_SET_ITEM(keypair,0,PyInt_FromLong(i));
|
||||
PyList_SetItem(keypair,1,PyInt_FromLong(inevent.m_status));
|
||||
PyList_Append(resultlist,keypair);
|
||||
}
|
||||
}
|
||||
return resultlist;
|
||||
}
|
||||
//<---- Deprecated
|
||||
|
||||
KX_PYMETHODDEF_DOC_O(SCA_KeyboardSensor, getKeyStatus,
|
||||
"getKeyStatus(keycode)\n"
|
||||
"\tGet the given key's status (KX_NO_INPUTSTATUS, KX_JUSTACTIVATED, KX_ACTIVE or KX_JUSTRELEASED).\n")
|
||||
{
|
||||
if (PyInt_Check(value))
|
||||
{
|
||||
int keycode = PyInt_AsLong(value);
|
||||
|
||||
if ((keycode < SCA_IInputDevice::KX_BEGINKEY)
|
||||
|| (keycode > SCA_IInputDevice::KX_ENDKEY)){
|
||||
PyErr_SetString(PyExc_AttributeError, "invalid keycode specified!");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
SCA_IInputDevice* inputdev = m_pKeyboardMgr->GetInputDevice();
|
||||
const SCA_InputEvent & inevent = inputdev->GetEventValue((SCA_IInputDevice::KX_EnumInputs) keycode);
|
||||
return PyInt_FromLong(inevent.m_status);
|
||||
if (!PyInt_Check(value)) {
|
||||
PyErr_SetString(PyExc_ValueError, "getKeyStatus expected an int");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
Py_RETURN_NONE;
|
||||
int keycode = PyInt_AsLong(value);
|
||||
|
||||
if ((keycode < SCA_IInputDevice::KX_BEGINKEY)
|
||||
|| (keycode > SCA_IInputDevice::KX_ENDKEY)){
|
||||
PyErr_SetString(PyExc_AttributeError, "invalid keycode specified!");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
SCA_IInputDevice* inputdev = m_pKeyboardMgr->GetInputDevice();
|
||||
const SCA_InputEvent & inevent = inputdev->GetEventValue((SCA_IInputDevice::KX_EnumInputs) keycode);
|
||||
return PyInt_FromLong(inevent.m_status);
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
@@ -824,6 +679,7 @@ PyMethodDef SCA_KeyboardSensor::Methods[] = {
|
||||
};
|
||||
|
||||
PyAttributeDef SCA_KeyboardSensor::Attributes[] = {
|
||||
KX_PYATTRIBUTE_RO_FUNCTION("events", SCA_KeyboardSensor, pyattr_get_events),
|
||||
KX_PYATTRIBUTE_BOOL_RW("useAllKeys",SCA_KeyboardSensor,m_bAllKeys),
|
||||
KX_PYATTRIBUTE_INT_RW("key",0,SCA_IInputDevice::KX_ENDKEY,true,SCA_KeyboardSensor,m_hotkey),
|
||||
KX_PYATTRIBUTE_SHORT_RW("hold1",0,SCA_IInputDevice::KX_ENDKEY,true,SCA_KeyboardSensor,m_qual),
|
||||
@@ -843,3 +699,175 @@ int SCA_KeyboardSensor::py_setattro(PyObject *attr, PyObject *value)
|
||||
{
|
||||
py_setattro_up(SCA_ISensor);
|
||||
}
|
||||
|
||||
|
||||
PyObject* SCA_KeyboardSensor::pyattr_get_events(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
|
||||
{
|
||||
SCA_KeyboardSensor* self= static_cast<SCA_KeyboardSensor*>(self_v);
|
||||
|
||||
SCA_IInputDevice* inputdev = self->m_pKeyboardMgr->GetInputDevice();
|
||||
|
||||
PyObject* resultlist = PyList_New(0);
|
||||
|
||||
for (int i=SCA_IInputDevice::KX_BEGINKEY ; i< SCA_IInputDevice::KX_ENDKEY;i++)
|
||||
{
|
||||
const SCA_InputEvent & inevent = inputdev->GetEventValue((SCA_IInputDevice::KX_EnumInputs) i);
|
||||
if (inevent.m_status != SCA_InputEvent::KX_NO_INPUTSTATUS)
|
||||
{
|
||||
PyObject* keypair = PyList_New(2);
|
||||
PyList_SET_ITEM(keypair,0,PyInt_FromLong(i));
|
||||
PyList_SetItem(keypair,1,PyInt_FromLong(inevent.m_status));
|
||||
PyList_Append(resultlist,keypair);
|
||||
}
|
||||
}
|
||||
return resultlist;
|
||||
}
|
||||
|
||||
|
||||
/* Accessed from python */
|
||||
|
||||
// this code looks ugly, please use an ordinary hashtable
|
||||
|
||||
char ToCharacter(int keyIndex, bool shifted)
|
||||
{
|
||||
/* numerals */
|
||||
if ( (keyIndex >= SCA_IInputDevice::KX_ZEROKEY)
|
||||
&& (keyIndex <= SCA_IInputDevice::KX_NINEKEY) ) {
|
||||
if (shifted) {
|
||||
char numshift[] = ")!@#$%^&*(";
|
||||
return numshift[keyIndex - '0'];
|
||||
} else {
|
||||
return keyIndex - SCA_IInputDevice::KX_ZEROKEY + '0';
|
||||
}
|
||||
}
|
||||
|
||||
/* letters... always lowercase... is that desirable? */
|
||||
if ( (keyIndex >= SCA_IInputDevice::KX_AKEY)
|
||||
&& (keyIndex <= SCA_IInputDevice::KX_ZKEY) ) {
|
||||
if (shifted) {
|
||||
return keyIndex - SCA_IInputDevice::KX_AKEY + 'A';
|
||||
} else {
|
||||
return keyIndex - SCA_IInputDevice::KX_AKEY + 'a';
|
||||
}
|
||||
}
|
||||
|
||||
if (keyIndex == SCA_IInputDevice::KX_SPACEKEY) {
|
||||
return ' ';
|
||||
}
|
||||
if (keyIndex == SCA_IInputDevice::KX_RETKEY || keyIndex == SCA_IInputDevice::KX_PADENTER) {
|
||||
return '\n';
|
||||
}
|
||||
|
||||
|
||||
if (keyIndex == SCA_IInputDevice::KX_PADASTERKEY) {
|
||||
return '*';
|
||||
}
|
||||
|
||||
if (keyIndex == SCA_IInputDevice::KX_TABKEY) {
|
||||
return '\t';
|
||||
}
|
||||
|
||||
/* comma to period */
|
||||
char commatoperiod[] = ",-.";
|
||||
char commatoperiodshifted[] = "<_>";
|
||||
if (keyIndex == SCA_IInputDevice::KX_COMMAKEY) {
|
||||
if (shifted) {
|
||||
return commatoperiodshifted[0];
|
||||
} else {
|
||||
return commatoperiod[0];
|
||||
}
|
||||
}
|
||||
if (keyIndex == SCA_IInputDevice::KX_MINUSKEY) {
|
||||
if (shifted) {
|
||||
return commatoperiodshifted[1];
|
||||
} else {
|
||||
return commatoperiod[1];
|
||||
}
|
||||
}
|
||||
if (keyIndex == SCA_IInputDevice::KX_PERIODKEY) {
|
||||
if (shifted) {
|
||||
return commatoperiodshifted[2];
|
||||
} else {
|
||||
return commatoperiod[2];
|
||||
}
|
||||
}
|
||||
|
||||
/* semicolon to rightbracket */
|
||||
char semicolontorightbracket[] = ";\'`/\\=[]";
|
||||
char semicolontorightbracketshifted[] = ":\"~\?|+{}";
|
||||
if ((keyIndex >= SCA_IInputDevice::KX_SEMICOLONKEY)
|
||||
&& (keyIndex <= SCA_IInputDevice::KX_RIGHTBRACKETKEY)) {
|
||||
if (shifted) {
|
||||
return semicolontorightbracketshifted[keyIndex - SCA_IInputDevice::KX_SEMICOLONKEY];
|
||||
} else {
|
||||
return semicolontorightbracket[keyIndex - SCA_IInputDevice::KX_SEMICOLONKEY];
|
||||
}
|
||||
}
|
||||
|
||||
/* keypad2 to padplus */
|
||||
char pad2topadplus[] = "246813579. 0- +";
|
||||
if ((keyIndex >= SCA_IInputDevice::KX_PAD2)
|
||||
&& (keyIndex <= SCA_IInputDevice::KX_PADPLUSKEY)) {
|
||||
return pad2topadplus[keyIndex - SCA_IInputDevice::KX_PAD2];
|
||||
}
|
||||
|
||||
return '!';
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Determine whether this character can be printed. We cannot use
|
||||
* the library functions here, because we need to test our own
|
||||
* keycodes. */
|
||||
bool IsPrintable(int keyIndex)
|
||||
{
|
||||
/* only print
|
||||
* - numerals: KX_ZEROKEY to KX_NINEKEY
|
||||
* - alphas: KX_AKEY to KX_ZKEY.
|
||||
* - specials: KX_RETKEY, KX_PADASTERKEY, KX_PADCOMMAKEY to KX_PERIODKEY,
|
||||
* KX_TABKEY , KX_SEMICOLONKEY to KX_RIGHTBRACKETKEY,
|
||||
* KX_PAD2 to KX_PADPLUSKEY
|
||||
* - delete and backspace: also printable in the sense that they modify
|
||||
* the string
|
||||
* - retkey: should this be printable?
|
||||
* - virgule: prints a space... don't know which key that's supposed
|
||||
* to be...
|
||||
*/
|
||||
if ( ((keyIndex >= SCA_IInputDevice::KX_ZEROKEY)
|
||||
&& (keyIndex <= SCA_IInputDevice::KX_NINEKEY))
|
||||
|| ((keyIndex >= SCA_IInputDevice::KX_AKEY)
|
||||
&& (keyIndex <= SCA_IInputDevice::KX_ZKEY))
|
||||
|| (keyIndex == SCA_IInputDevice::KX_SPACEKEY)
|
||||
|| (keyIndex == SCA_IInputDevice::KX_RETKEY)
|
||||
|| (keyIndex == SCA_IInputDevice::KX_PADENTER)
|
||||
|| (keyIndex == SCA_IInputDevice::KX_PADASTERKEY)
|
||||
|| (keyIndex == SCA_IInputDevice::KX_TABKEY)
|
||||
|| ((keyIndex >= SCA_IInputDevice::KX_COMMAKEY)
|
||||
&& (keyIndex <= SCA_IInputDevice::KX_PERIODKEY))
|
||||
|| ((keyIndex >= SCA_IInputDevice::KX_SEMICOLONKEY)
|
||||
&& (keyIndex <= SCA_IInputDevice::KX_RIGHTBRACKETKEY))
|
||||
|| ((keyIndex >= SCA_IInputDevice::KX_PAD2)
|
||||
&& (keyIndex <= SCA_IInputDevice::KX_PADPLUSKEY))
|
||||
|| (keyIndex == SCA_IInputDevice::KX_DELKEY)
|
||||
|| (keyIndex == SCA_IInputDevice::KX_BACKSPACEKEY)
|
||||
)
|
||||
{
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests whether this is a delete key.
|
||||
*/
|
||||
bool IsDelete(int keyIndex)
|
||||
{
|
||||
if ( (keyIndex == SCA_IInputDevice::KX_DELKEY)
|
||||
|| (keyIndex == SCA_IInputDevice::KX_BACKSPACEKEY) ) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -81,22 +81,6 @@ class SCA_KeyboardSensor : public SCA_ISensor
|
||||
*/
|
||||
void AddToTargetProp(int keyIndex);
|
||||
|
||||
/**
|
||||
* Determine whether this character can be printed. We cannot use
|
||||
* the library functions here, because we need to test our own
|
||||
* keycodes. */
|
||||
bool IsPrintable(int keyIndex);
|
||||
|
||||
/**
|
||||
* Transform keycodes to something printable.
|
||||
*/
|
||||
char ToCharacter(int keyIndex, bool shifted);
|
||||
|
||||
/**
|
||||
* Tests whether this is a delete key.
|
||||
*/
|
||||
bool IsDelete(int keyIndex);
|
||||
|
||||
/**
|
||||
* Tests whether shift is pressed.
|
||||
*/
|
||||
@@ -152,7 +136,29 @@ public:
|
||||
KX_PYMETHOD_DOC_NOARGS(SCA_KeyboardSensor,getEventList);
|
||||
// KeyStatus:
|
||||
KX_PYMETHOD_DOC_O(SCA_KeyboardSensor,getKeyStatus);
|
||||
|
||||
static PyObject* pyattr_get_events(void* self_v, const KX_PYATTRIBUTE_DEF *attrdef);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Transform keycodes to something printable.
|
||||
*/
|
||||
char ToCharacter(int keyIndex, bool shifted);
|
||||
|
||||
/**
|
||||
* Determine whether this character can be printed. We cannot use
|
||||
* the library functions here, because we need to test our own
|
||||
* keycodes. */
|
||||
bool IsPrintable(int keyIndex);
|
||||
|
||||
/**
|
||||
* Tests whether this is a delete key.
|
||||
*/
|
||||
bool IsDelete(int keyIndex);
|
||||
|
||||
|
||||
#endif //__KX_KEYBOARDSENSOR
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -54,6 +54,7 @@
|
||||
#include "SCA_IInputDevice.h"
|
||||
#include "SCA_PropertySensor.h"
|
||||
#include "SCA_RandomActuator.h"
|
||||
#include "SCA_KeyboardSensor.h" /* IsPrintable, ToCharacter */
|
||||
#include "KX_ConstraintActuator.h"
|
||||
#include "KX_IpoActuator.h"
|
||||
#include "KX_SoundActuator.h"
|
||||
@@ -162,7 +163,7 @@ static PyObject* gPyExpandPath(PyObject*, PyObject* args)
|
||||
char expanded[FILE_MAXDIR + FILE_MAXFILE];
|
||||
char* filename;
|
||||
|
||||
if (!PyArg_ParseTuple(args,"s",&filename))
|
||||
if (!PyArg_ParseTuple(args,"s:ExpandPath",&filename))
|
||||
return NULL;
|
||||
|
||||
BLI_strncpy(expanded, filename, FILE_MAXDIR + FILE_MAXFILE);
|
||||
@@ -185,7 +186,7 @@ static PyObject* gPySendMessage(PyObject*, PyObject* args)
|
||||
char* to = "";
|
||||
char* from = "";
|
||||
|
||||
if (!PyArg_ParseTuple(args, "s|sss", &subject, &body, &to, &from))
|
||||
if (!PyArg_ParseTuple(args, "s|sss:sendMessage", &subject, &body, &to, &from))
|
||||
return NULL;
|
||||
|
||||
gp_KetsjiScene->GetNetworkScene()->SendMessage(to, from, subject, body);
|
||||
@@ -268,7 +269,7 @@ static PyObject* gPyStopDSP(PyObject*, PyObject* args)
|
||||
static PyObject* gPySetLogicTicRate(PyObject*, PyObject* args)
|
||||
{
|
||||
float ticrate;
|
||||
if (!PyArg_ParseTuple(args, "f", &ticrate))
|
||||
if (!PyArg_ParseTuple(args, "f:setLogicTicRate", &ticrate))
|
||||
return NULL;
|
||||
|
||||
KX_KetsjiEngine::SetTicRate(ticrate);
|
||||
@@ -283,7 +284,7 @@ static PyObject* gPyGetLogicTicRate(PyObject*)
|
||||
static PyObject* gPySetPhysicsTicRate(PyObject*, PyObject* args)
|
||||
{
|
||||
float ticrate;
|
||||
if (!PyArg_ParseTuple(args, "f", &ticrate))
|
||||
if (!PyArg_ParseTuple(args, "f:setPhysicsTicRate", &ticrate))
|
||||
return NULL;
|
||||
|
||||
PHY_GetActiveEnvironment()->setFixedTimeStep(true,ticrate);
|
||||
@@ -293,7 +294,7 @@ static PyObject* gPySetPhysicsTicRate(PyObject*, PyObject* args)
|
||||
static PyObject* gPySetPhysicsDebug(PyObject*, PyObject* args)
|
||||
{
|
||||
int debugMode;
|
||||
if (!PyArg_ParseTuple(args, "i", &debugMode))
|
||||
if (!PyArg_ParseTuple(args, "i:setPhysicsDebug", &debugMode))
|
||||
return NULL;
|
||||
|
||||
PHY_GetActiveEnvironment()->setDebugMode(debugMode);
|
||||
@@ -321,7 +322,7 @@ static PyObject* gPyGetBlendFileList(PyObject*, PyObject* args)
|
||||
DIR *dp;
|
||||
struct dirent *dirp;
|
||||
|
||||
if (!PyArg_ParseTuple(args, "|s", &searchpath))
|
||||
if (!PyArg_ParseTuple(args, "|s:getBlendFileList", &searchpath))
|
||||
return NULL;
|
||||
|
||||
list = PyList_New(0);
|
||||
@@ -507,7 +508,7 @@ bool gUseVisibilityTemp = false;
|
||||
static PyObject* gPyEnableVisibility(PyObject*, PyObject* args)
|
||||
{
|
||||
int visible;
|
||||
if (!PyArg_ParseTuple(args,"i",&visible))
|
||||
if (!PyArg_ParseTuple(args,"i:enableVisibility",&visible))
|
||||
return NULL;
|
||||
|
||||
gUseVisibilityTemp = (visible != 0);
|
||||
@@ -519,7 +520,7 @@ static PyObject* gPyEnableVisibility(PyObject*, PyObject* args)
|
||||
static PyObject* gPyShowMouse(PyObject*, PyObject* args)
|
||||
{
|
||||
int visible;
|
||||
if (!PyArg_ParseTuple(args,"i",&visible))
|
||||
if (!PyArg_ParseTuple(args,"i:showMouse",&visible))
|
||||
return NULL;
|
||||
|
||||
if (visible)
|
||||
@@ -540,7 +541,7 @@ static PyObject* gPyShowMouse(PyObject*, PyObject* args)
|
||||
static PyObject* gPySetMousePosition(PyObject*, PyObject* args)
|
||||
{
|
||||
int x,y;
|
||||
if (!PyArg_ParseTuple(args,"ii",&x,&y))
|
||||
if (!PyArg_ParseTuple(args,"ii:setMousePosition",&x,&y))
|
||||
return NULL;
|
||||
|
||||
if (gp_Canvas)
|
||||
@@ -552,7 +553,7 @@ static PyObject* gPySetMousePosition(PyObject*, PyObject* args)
|
||||
static PyObject* gPySetEyeSeparation(PyObject*, PyObject* args)
|
||||
{
|
||||
float sep;
|
||||
if (!PyArg_ParseTuple(args, "f", &sep))
|
||||
if (!PyArg_ParseTuple(args, "f:setEyeSeparation", &sep))
|
||||
return NULL;
|
||||
|
||||
if (!gp_Rasterizer) {
|
||||
@@ -565,7 +566,7 @@ static PyObject* gPySetEyeSeparation(PyObject*, PyObject* args)
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
static PyObject* gPyGetEyeSeparation(PyObject*, PyObject*, PyObject*)
|
||||
static PyObject* gPyGetEyeSeparation(PyObject*)
|
||||
{
|
||||
if (!gp_Rasterizer) {
|
||||
PyErr_SetString(PyExc_RuntimeError, "Rasterizer not available");
|
||||
@@ -578,7 +579,7 @@ static PyObject* gPyGetEyeSeparation(PyObject*, PyObject*, PyObject*)
|
||||
static PyObject* gPySetFocalLength(PyObject*, PyObject* args)
|
||||
{
|
||||
float focus;
|
||||
if (!PyArg_ParseTuple(args, "f", &focus))
|
||||
if (!PyArg_ParseTuple(args, "f:setFocalLength", &focus))
|
||||
return NULL;
|
||||
|
||||
if (!gp_Rasterizer) {
|
||||
@@ -641,7 +642,7 @@ static PyObject* gPySetMistStart(PyObject*, PyObject* args)
|
||||
{
|
||||
|
||||
float miststart;
|
||||
if (!PyArg_ParseTuple(args,"f",&miststart))
|
||||
if (!PyArg_ParseTuple(args,"f:setMistStart",&miststart))
|
||||
return NULL;
|
||||
|
||||
if (!gp_Rasterizer) {
|
||||
@@ -660,7 +661,7 @@ static PyObject* gPySetMistEnd(PyObject*, PyObject* args)
|
||||
{
|
||||
|
||||
float mistend;
|
||||
if (!PyArg_ParseTuple(args,"f",&mistend))
|
||||
if (!PyArg_ParseTuple(args,"f:setMistEnd",&mistend))
|
||||
return NULL;
|
||||
|
||||
if (!gp_Rasterizer) {
|
||||
@@ -696,7 +697,7 @@ static PyObject* gPySetAmbientColor(PyObject*, PyObject* value)
|
||||
static PyObject* gPyMakeScreenshot(PyObject*, PyObject* args)
|
||||
{
|
||||
char* filename;
|
||||
if (!PyArg_ParseTuple(args,"s",&filename))
|
||||
if (!PyArg_ParseTuple(args,"s:makeScreenshot",&filename))
|
||||
return NULL;
|
||||
|
||||
if (gp_Canvas)
|
||||
@@ -710,7 +711,7 @@ static PyObject* gPyMakeScreenshot(PyObject*, PyObject* args)
|
||||
static PyObject* gPyEnableMotionBlur(PyObject*, PyObject* args)
|
||||
{
|
||||
float motionblurvalue;
|
||||
if (!PyArg_ParseTuple(args,"f",&motionblurvalue))
|
||||
if (!PyArg_ParseTuple(args,"f:enableMotionBlur",&motionblurvalue))
|
||||
return NULL;
|
||||
|
||||
if (!gp_Rasterizer) {
|
||||
@@ -760,7 +761,7 @@ static PyObject* gPySetGLSLMaterialSetting(PyObject*,
|
||||
char *setting;
|
||||
int enable, flag, fileflags;
|
||||
|
||||
if (!PyArg_ParseTuple(args,"si",&setting,&enable))
|
||||
if (!PyArg_ParseTuple(args,"si:setGLSLMaterialSetting",&setting,&enable))
|
||||
return NULL;
|
||||
|
||||
flag = getGLSLSettingFlag(setting);
|
||||
@@ -801,7 +802,7 @@ static PyObject* gPyGetGLSLMaterialSetting(PyObject*,
|
||||
char *setting;
|
||||
int enabled = 0, flag;
|
||||
|
||||
if (!PyArg_ParseTuple(args,"s",&setting))
|
||||
if (!PyArg_ParseTuple(args,"s:getGLSLMaterialSetting",&setting))
|
||||
return NULL;
|
||||
|
||||
flag = getGLSLSettingFlag(setting);
|
||||
@@ -825,7 +826,7 @@ static PyObject* gPySetMaterialType(PyObject*,
|
||||
{
|
||||
int flag, type;
|
||||
|
||||
if (!PyArg_ParseTuple(args,"i",&type))
|
||||
if (!PyArg_ParseTuple(args,"i:setMaterialType",&type))
|
||||
return NULL;
|
||||
|
||||
if(type == KX_BLENDER_GLSL_MATERIAL)
|
||||
@@ -870,7 +871,7 @@ static PyObject* gPyDrawLine(PyObject*, PyObject* args)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (!PyArg_ParseTuple(args,"OOO",&ob_from,&ob_to,&ob_color))
|
||||
if (!PyArg_ParseTuple(args,"OOO:drawLine",&ob_from,&ob_to,&ob_color))
|
||||
return NULL;
|
||||
|
||||
MT_Vector3 from;
|
||||
@@ -911,7 +912,7 @@ static struct PyMethodDef rasterizer_methods[] = {
|
||||
|
||||
|
||||
{"setEyeSeparation", (PyCFunction) gPySetEyeSeparation, METH_VARARGS, "set the eye separation for stereo mode"},
|
||||
{"getEyeSeparation", (PyCFunction) gPyGetEyeSeparation, METH_VARARGS, "get the eye separation for stereo mode"},
|
||||
{"getEyeSeparation", (PyCFunction) gPyGetEyeSeparation, METH_NOARGS, "get the eye separation for stereo mode"},
|
||||
{"setFocalLength", (PyCFunction) gPySetFocalLength, METH_VARARGS, "set the focal length for stereo mode"},
|
||||
{"getFocalLength", (PyCFunction) gPyGetFocalLength, METH_VARARGS, "get the focal length for stereo mode"},
|
||||
{"setMaterialMode",(PyCFunction) gPySetMaterialType,
|
||||
@@ -1462,7 +1463,7 @@ static char GameKeys_module_documentation[] =
|
||||
;
|
||||
|
||||
static char gPyEventToString_doc[] =
|
||||
"Take a valid event from the GameKeys module or Keyboard Sensor and return a name"
|
||||
"EventToString(event) - Take a valid event from the GameKeys module or Keyboard Sensor and return a name"
|
||||
;
|
||||
|
||||
static PyObject* gPyEventToString(PyObject*, PyObject* value)
|
||||
@@ -1491,7 +1492,29 @@ static PyObject* gPyEventToString(PyObject*, PyObject* value)
|
||||
return ret;
|
||||
}
|
||||
|
||||
static char gPyEventToCharacter_doc[] =
|
||||
"EventToCharacter(event, is_shift) - Take a valid event from the GameKeys module or Keyboard Sensor and return a character"
|
||||
;
|
||||
|
||||
static PyObject* gPyEventToCharacter(PyObject*, PyObject* args)
|
||||
{
|
||||
int event, shift;
|
||||
if (!PyArg_ParseTuple(args,"ii:EventToCharacter", &event, &shift))
|
||||
return NULL;
|
||||
|
||||
if(IsPrintable(event)) {
|
||||
char ch[2] = {'\0', '\0'};
|
||||
ch[0] = ToCharacter(event, (bool)shift);
|
||||
return PyString_FromString(ch);
|
||||
}
|
||||
else {
|
||||
return PyString_FromString("");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static struct PyMethodDef gamekeys_methods[] = {
|
||||
{"EventToCharacter", (PyCFunction)gPyEventToCharacter, METH_VARARGS, (PY_METHODCHAR)gPyEventToCharacter_doc},
|
||||
{"EventToString", (PyCFunction)gPyEventToString, METH_O, (PY_METHODCHAR)gPyEventToString_doc},
|
||||
{ NULL, (PyCFunction) NULL, 0, NULL }
|
||||
};
|
||||
|
||||
@@ -134,26 +134,20 @@ Example::
|
||||
co = GameLogic.getCurrentController()
|
||||
# 'Keyboard' is a keyboard sensor
|
||||
sensor = co.getSensor('Keyboard')
|
||||
sensor.setKey(GameKeys.F1KEY)
|
||||
sensor.key = GameKeys.F1KEY
|
||||
|
||||
Example::
|
||||
# Do the all keys thing
|
||||
import GameLogic
|
||||
import GameKeys
|
||||
|
||||
# status: these should be added to a module somewhere
|
||||
KX_NO_INPUTSTATUS = 0
|
||||
KX_JUSTACTIVATED = 1
|
||||
KX_ACTIVE = 2
|
||||
KX_JUSTRELEASED = 3
|
||||
|
||||
|
||||
co = GameLogic.getCurrentController()
|
||||
# 'Keyboard' is a keyboard sensor
|
||||
sensor = co.getSensor('Keyboard')
|
||||
keylist = sensor.getPressedKeys()
|
||||
keylist = sensor.events
|
||||
for key in keylist:
|
||||
# key[0] == GameKeys.keycode, key[1] = status
|
||||
if key[1] == KX_JUSTACTIVATED:
|
||||
if key[1] == GameLogic.KX_INPUT_JUST_ACTIVATED:
|
||||
if key[0] == GameKeys.WKEY:
|
||||
# Activate Forward!
|
||||
if key[0] == GameKeys.SKEY:
|
||||
@@ -173,3 +167,15 @@ def EventToString(event):
|
||||
@param event: key event from GameKeys or the keyboard sensor.
|
||||
@rtype: string
|
||||
"""
|
||||
|
||||
def EventToCharacter(event, shift):
|
||||
"""
|
||||
Return the string name of a key event. Returns an empty string if the event cant be represented as a character.
|
||||
|
||||
@type event: int
|
||||
@param event: key event from GameKeys or the keyboard sensor.
|
||||
@type event: bool
|
||||
@param event: set to true if shift is held.
|
||||
@rtype: string
|
||||
"""
|
||||
|
||||
|
||||
Reference in New Issue
Block a user