首页 > 解决方案 > 在 python 中使用 Logitech C 库 - 定义结构和回调

问题描述

我想在 python 代码中包装/使用 Logitech C/C++ 库:

  1. http://gaming.logitech.com/sdk/LCDSDK_8.57.1​​48.zip
  2. https://www.logitechg.com/sdk/LED_SDK_9.00.zip
  3. http://gaming.logitech.com/sdk/GkeySDK_8.57.1​​48.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);

参数:

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

标签: pythonc++ctypespython-c-apilogitech-gaming-software

解决方案


推荐阅读