[pywin32-checkins] pywin32/win32/src win32apimodule.cpp, 1.101, 1.102
OLD project page for the Python extensions for Windows
Brought to you by:
mhammond
From: Mark H. <mha...@us...> - 2010-08-27 02:47:28
|
Update of /cvsroot/pywin32/pywin32/win32/src In directory sfp-cvsdas-2.v30.ch3.sourceforge.com:/tmp/cvs-serv439/win32/src Modified Files: win32apimodule.cpp Log Message: New win32api functions GetKeyboardLayoutName, MapVirtualKey and ToAsciiEx Index: win32apimodule.cpp =================================================================== RCS file: /cvsroot/pywin32/pywin32/win32/src/win32apimodule.cpp,v retrieving revision 1.101 retrieving revision 1.102 diff -C2 -d -r1.101 -r1.102 *** win32apimodule.cpp 25 Aug 2010 07:34:59 -0000 1.101 --- win32apimodule.cpp 27 Aug 2010 02:47:20 -0000 1.102 *************** *** 5956,5959 **** --- 5956,5970 ---- } + // @pymethod int|win32api|GetKeyboardLayoutName|Retrieves the name of the active input locale identifier (formerly called the keyboard layout). + PyObject *PyGetKeyboardLayoutName(PyObject *self, PyObject *args) + { + if (!PyArg_ParseTuple(args,":GetKeyboardLayoutName")) + return NULL; + WCHAR buf[KL_NAMELENGTH+1]; + if (!::GetKeyboardLayoutNameW(buf)) + return PyWin_SetAPIError("GetKeyboardLayoutNameW"); + return PyWinObject_FromWCHAR(buf); + } + // @pymethod (int,..)|win32api|GetKeyboardLayoutList|Returns a sequence of all locale ids currently loaded PyObject *PyGetKeyboardLayoutList(PyObject *self, PyObject *args) *************** *** 6009,6012 **** --- 6020,6076 ---- } + // @pymethod bytes|win32api|ToAsciiEx|Translates the specified virtual-key code and keyboard state to the corresponding character or characters. + PyObject *PyToAsciiEx(PyObject *self, PyObject *args) + { + UINT vk, sc, flags=0; + const char *state; + int statesize; + PyObject *obhlayout = NULL; + HKL layout = 0; + // @pyparm int|vk||The virtual key code. + // @pyparm int|scancode||The scan code. + // @pyparm bytes|keyboardstate||A string of exactly 256 characters. + // @pyparm int|flags|0| + // @pyparm handle|hlayout|None|The keyboard layout to use + if (!PyArg_ParseTuple(args, "iis#|iO", &vk, &sc, &state, &statesize, &flags, obhlayout)) + return NULL; + if (statesize!=256) + return PyErr_Format(PyExc_ValueError, "keyboard state string must be exactly 256 characters"); + if (obhlayout && !PyWinObject_AsHANDLE(obhlayout, (HANDLE *)&layout)) + return NULL; + char result[2]; + int nc = ToAsciiEx(vk,sc,(BYTE *)state,(unsigned short *)result,flags,layout); + if (nc < 0) { // a dead char. + Py_INCREF(Py_None); + return Py_None; + } + return PyString_FromStringAndSize(result, nc); + } + + // @pymethod int|win32api|MapVirtualKey|Translates (maps) a virtual-key code into a scan code or character value, or translates a scan code into a virtual-key code. + // @comm implemented by calling the unicode versions of the API (MapVirtualKeyW/MapVirtualKeyExW) + PyObject *PyMapVirtualKey(PyObject *self, PyObject *args) + { + UINT vk, typ; + PyObject *obhlayout = NULL; + HKL layout = 0; + // @pyparm int|vk||The virtual key code. + // @pyparm int|type||The type of conversion to make - see the API + // @pyparm handle|hlayout|None|The keyboard layout to use. If not + // specified, the API function MapVirtualKey will be called. If it + // is specified MapVirtualKeyEx will be called. + if (!PyArg_ParseTuple(args, "ii|O", &vk, &typ, obhlayout)) + return NULL; + int rc; + if (obhlayout==NULL) { + rc = MapVirtualKeyW(vk, typ); + } else{ + if (!PyWinObject_AsHANDLE(obhlayout, (HANDLE *)&layout)) + return NULL; + rc = MapVirtualKeyExW(vk, typ, layout); + } + return PyInt_FromLong(rc); + } + // @pymethod dict|win32api|GlobalMemoryStatus|Returns systemwide memory usage // @rdesc Returns a dictionary representing a MEMORYSTATUS structure *************** *** 6208,6211 **** --- 6272,6276 ---- {"GetKeyboardLayout", PyGetKeyboardLayout, 1}, // @pymeth GetKeyboardLayout|Retrieves the active input locale identifier {"GetKeyboardLayoutList", PyGetKeyboardLayoutList, 1}, // @pymeth GetKeyboardLayoutList|Returns a sequence of all locale ids in the system + {"GetKeyboardLayoutName", PyGetKeyboardLayoutName, 1}, // @pymeth GetKeyboardLayoutName|Retrieves the name of the active input locale identifier (formerly called the keyboard layout). {"GetKeyboardState", PyGetKeyboardState, 1}, // @pymeth GetKeyboardState|Retrieves the status of the 256 virtual keys on the keyboard. {"GetKeyState", PyGetKeyState, 1}, // @pymeth GetKeyState|Retrives the last known key state for a key. *************** *** 6269,6272 **** --- 6334,6338 ---- {"LoadResource", PyLoadResource,1}, // @pymeth LoadResource|Finds and loads a resource from a PE file. {"LoadString", PyLoadString,1}, // @pymeth LoadString|Loads a string from a resource file. + {"MapVirtualKey", PyMapVirtualKey,1}, // @pymeth MapVirtualKeyEx|Translates (maps) a virtual-key code into a scan code or character value, or translates a scan code into a virtual-key code. {"MessageBeep", PyMessageBeep,1}, // @pymeth MessageBeep|Plays a predefined waveform sound. {"MessageBoxEx", PyMessageBox, 1}, *************** *** 6349,6352 **** --- 6415,6419 ---- {"SleepEx", PySleep, 1}, // @pymeth Sleep|Suspends current application execution {"TerminateProcess", PyTerminateProcess, 1}, // @pymeth TerminateProcess|Terminates a process. + {"ToAsciiEx", PyToAsciiEx, 1}, // @pymeth ToAsciiEx|Translates the specified virtual-key code and keyboard state to the corresponding character or characters. {"Unicode", PyWin_NewUnicode, 1}, // @pymeth Unicode|Creates a new <o PyUnicode> object {"UpdateResource", PyUpdateResource, 1 }, // @pymeth UpdateResource|Updates a resource in a PE file. |