python - 在 python 中使用 Logitech C 库 - 定义结构和回调
问题描述
我想在 python 代码中包装/使用 Logitech C/C++ 库:
- http://gaming.logitech.com/sdk/LCDSDK_8.57.148.zip
- https://www.logitechg.com/sdk/LED_SDK_9.00.zip
- http://gaming.logitech.com/sdk/GkeySDK_8.57.148.zip
即使对我来说,前两个(LCD 和 LED)也很容易。您需要下载 zips 并且有一个 pdf 参考文件,即:python for LCD:
from ctypes import CDLL, c_bool, c_wchar_p, c_int
lcd_dll = CDLL('C:\\Program Files\\Logitech Gaming Software\\LCDSDK_8.57.148\\Lib\\GameEnginesWrapper\\x64\\LogitechLcdEnginesWrapper.dll')
LogiLcdInit = lcd_dll['LogiLcdInit']
LogiLcdInit.restype = c_bool
LogiLcdInit.argtypes = (c_wchar_p, c_int)
LogiLcdIsConnected = lcd_dll['LogiLcdIsConnected']
LogiLcdIsConnected.restype = c_bool
LogiLcdIsConnected.argtypes = [c_int]
我对第 3 个 Gkey 有疑问,请查看第 16 页和第 17 页 - logiGkeyCBContext 结构。为了打电话LogiGkeyInit()
,我需要:
LogiGkeyInit ()函数初始化 G-key SDK。必须在您的应用程序可以看到 G 键/按钮事件之前调用它。
BOOL LogiGkeyInit(logiGkeyCBContext* gkeyCBContext);
参数:
- gkeyCBContext:回调的上下文。请参阅上面的示例代码或 Samples 文件夹中的示例程序。这个值
logiGkeyCBContext用于为 SDK 提供足够的信息,以允许将 G 键事件发送回您的应用程序。当用户按下/释放 G 键/鼠标按钮时调用注册的回调,并且 SDK 客户端当前处于前台。
typedef struct
{
logiGkeyCB gkeyCallBack;
void* gkeyContext;
} logiGkeyCBContext;
typedef struct
{
unsigned int keyIdx : 8; // index of the G key or mouse button, for example, 6 for G6 or Button 6
unsigned int keyDown : 1; // key up or down, 1 is down, 0 is up
unsigned int mState : 2; // mState (1, 2 or 3 for M1, M2 and M3)
unsigned int mouse : 1; // indicate if the Event comes from a mouse, 1 is yes, 0 is no.
unsigned int reserved1 : 4; // reserved1
unsigned int reserved2 : 16; // reserved2
} GkeyCode;
回调函数 logiGkeyCB 定义如下:
typedef void (__cdecl *logiGkeyCB)(GkeyCode gkeyCode, const wchar_t* gkeyOrButtonString, void* context);
问题
那么,我如何在 python 中定义所有这些东西来调用和使用它。我想使用LogiGkeyIsKeyboardGkeyPressed()
,LogiGkeyGetKeyboardGkeyString()
所以我需要LogiGkeyInit()
和方法在 python中定义回调logiGkeyCBContext
解决方案
推荐阅读
- ajax - 部署到 Azure 后 Ajax 无法正常工作
- wordpress - 如何使用 wp_query 仅在主要分类中获取帖子?
- markdown - 如何在 Markdown 的待办事项列表上标记失败的项目?
- java - 如何从 Firebase 检索数据以在 Android 地图上制作多个标记
- c# - C# DateTimeKind.Local 是指计算机还是业务对象?
- ecmascript-6 - 通过 gulp.js 将 ES6 转译为 ES5
- mysql - 如何优化与区域相关的 MYSQL 查询
- c# - 无法从 webapi 接收令牌并在 Angular 6 中显示
- javascript - 如何分别启用对所有循环图像的点击
- sql-server - 如何在 SELECT 中排除相同的行