private unsafe void OnPressAndReleaseDelegateFunc(ref HotKey_API.IMC_HOTKEY_MSG_OBJECT msg) { byte[] byKeyBuf = new byte[HotKey_API.IMC_HOTKEY_BUFFER_SIZE]; unsafe { fixed(byte *pDst = byKeyBuf) { fixed(byte *pSrc = msg.buf) { IMCWin32API.CopyMemory(pDst, pSrc, HotKey_API.IMC_HOTKEY_BUFFER_SIZE); } } } BeginInvoke(ShowHotKeyStatusDelegateFunc, byKeyBuf); }
// The thread function of reading hot key status private void ReadHotKeyStatusWorkerThread() { ushort ret; HotKey_API.IMC_HOTKEY_MSG_OBJECT msg = new HotKey_API.IMC_HOTKEY_MSG_OBJECT(); byte[] byKeyBuf = new byte[HotKey_API.IMC_HOTKEY_BUFFER_SIZE]; nReadHotKeyStatusExit = 0; while (nReadHotKeyStatusExit == 0) { // Read hot key status from the registers ret = HotKey_API.HotKey_Read(out msg); if (ret != IMCAPIErrCode.IMC_ERR_NO_ERROR && ret != IMCAPIErrCode.IMC_ERR_TIME_OUT && ret != IMCAPIErrCode.IMC_ERR_NON_ANY_KEY_PRESS ) { ShowWanringMessage("Fails to read the values of key status", ret); AutoEvtReadHotKeyStatus.Set(); return; } unsafe { fixed(byte *pDst = byKeyBuf) { byte *pSrc = msg.buf; { IMCWin32API.CopyMemory(pDst, pSrc, HotKey_API.IMC_HOTKEY_BUFFER_SIZE); } } } BeginInvoke(ShowHotKeyStatusDelegateFunc, byKeyBuf); Thread.Sleep(10); } Thread.Sleep(0); AutoEvtReadHotKeyStatus.Set(); }