📄 winwindow.cc
字号:
}
else if ((res == 1) || (res < 0))
{
asciiCode = ascii[0];
}
InputEvent event;
event.deviceInst = 0;
event.deviceType = KeyboardDeviceType;
event.objType = SI_KEY;
event.objInst = newVirtKey;
event.action = make ? (repeat ? SI_REPEAT : SI_MAKE ) : SI_BREAK;
event.modifier = modKey;
event.ascii = asciiCode;
event.fValue = make ? 1.0 : 0.0;
#ifdef LOG_INPUT
char keyName[25];
GetKeyNameText( lParam, keyName, 24 );
if ( event.action == SI_MAKE )
Input::log( "EVENT (Win): %s key pressed (Repeat count: %d). MODS:%c%c%c\n", keyName, repeatCount,
( modKey & SI_SHIFT ? 'S' : '.' ),
( modKey & SI_CTRL ? 'C' : '.' ),
( modKey & SI_ALT ? 'A' : '.' ) );
else
Input::log( "EVENT (Win): %s key released.\n", keyName );
#endif
Game->postEvent(event);
}
static void processCharMessage( WPARAM wParam, LPARAM lParam )
{
TCHAR charCode = wParam;
UTF16 tmpString[2] = { charCode, 0 };
UTF8 out[256];
convertUTF16toUTF8(tmpString, out, 250);
// Con::printf("Got IME char code %x (%s)", charCode, out);
InputEvent event;
event.deviceInst = 0;
event.deviceType = KeyboardDeviceType;
event.objType = SI_KEY;
event.action = SI_MAKE;
event.ascii = charCode;
// Deal with some silly cases like <BS>. This might be indicative of a
// missing MapVirtualKey step, not quite sure how to deal with this.
if(event.ascii == 0x8)
event.objInst = KEY_BACKSPACE; // Note we abuse objInst.
Game->postEvent(event);
// And put it back up as well, they can't hold it!
event.action = SI_BREAK;
Game->postEvent(event);
}
//--------------------------------------
//IME Chinese
static void ProcessGBMessage(UINT message, WPARAM wParam, LPARAM lParam)
{
//ascii处理
if(!IsGB(wParam))
{
processKeyMessage( message, wParam, lParam);
return;
}
static char szBuffer[4]={0};
static S32 nCursor = 1;
szBuffer[nCursor--] = wParam;
if(nCursor < 0 ) //每1完整GB字符发送一次
{
InputEvent event;
//S32 repeatCount = lParam & 0xFFFF;
event.deviceInst = 0;
event.deviceType = KeyboardDeviceType;
event.objType = SI_GBCHAR;
event.objInst = 0;
event.action = SI_MAKE;// ) : SI_BREAK;
event.modifier = 0;
event.ascii = *(U16*)szBuffer;
//event.fValue = 0.0;
nCursor = 1;
Game->postEvent(event);
}
}
static S32 mouseX = 0xFFFFFFFF;
static S32 mouseY = 0xFFFFFFFF;
//--------------------------------------
static void CheckCursorPos()
{
if(windowLocked && windowActive)
{
POINT mousePos;
GetCursorPos(&mousePos);
RECT r;
GetWindowRect(winState.appWindow, &r);
S32 centerX = (r.right + r.left) >> 1;
S32 centerY = (r.bottom + r.top) >> 1;
if(mousePos.x != centerX)
{
InputEvent event;
event.deviceInst = 0;
event.deviceType = MouseDeviceType;
event.objType = SI_XAXIS;
event.objInst = 0;
event.action = SI_MOVE;
event.modifier = modifierKeys;
event.ascii = 0;
event.fValue = (mousePos.x - centerX);
Game->postEvent(event);
}
if(mousePos.y != centerY)
{
InputEvent event;
event.deviceInst = 0;
event.deviceType = MouseDeviceType;
event.objType = SI_YAXIS;
event.objInst = 0;
event.action = SI_MOVE;
event.modifier = modifierKeys;
event.ascii = 0;
event.fValue = (mousePos.y - centerY);
Game->postEvent(event);
}
SetCursorPos(centerX, centerY);
}
}
//--------------------------------------
static void mouseButtonEvent(S32 action, S32 objInst)
{
CheckCursorPos();
if(!windowLocked)
{
if(action == SI_MAKE)
SetCapture(winState.appWindow);
else
ReleaseCapture();
}
U32 buttonId = objInst - KEY_BUTTON0;
if ( buttonId < 3 )
mouseButtonState[buttonId] = ( action == SI_MAKE ) ? true : false;
InputEvent event;
event.deviceInst = 0;
event.deviceType = MouseDeviceType;
event.objType = SI_BUTTON;
event.objInst = objInst;
event.action = action;
event.modifier = modifierKeys;
event.ascii = 0;
event.fValue = action == SI_MAKE ? 1.0 : 0.0;
#ifdef LOG_INPUT
if ( action == SI_MAKE )
Input::log( "EVENT (Win): mouse button%d pressed. MODS:%c%c%c\n", buttonId, ( modifierKeys & SI_SHIFT ? 'S' : '.' ), ( modifierKeys & SI_CTRL ? 'C' : '.' ), ( modifierKeys & SI_ALT ? 'A' : '.' ) );
else
Input::log( "EVENT (Win): mouse button%d released.\n", buttonId );
#endif
Game->postEvent(event);
}
//--------------------------------------
static void mouseWheelEvent( S32 delta )
{
static S32 _delta = 0;
_delta += delta;
if ( abs( delta ) >= WHEEL_DELTA )
{
_delta = 0;
InputEvent event;
event.deviceInst = 0;
event.deviceType = MouseDeviceType;
event.objType = SI_ZAXIS;
event.objInst = 0;
event.action = SI_MOVE;
event.modifier = modifierKeys;
event.ascii = 0;
event.fValue = delta;
#ifdef LOG_INPUT
Input::log( "EVENT (Win): mouse wheel moved. delta = %d\n", delta );
#endif
Game->postEvent( event );
}
}
struct WinMessage
{
UINT message;
WPARAM wParam;
LPARAM lParam;
WinMessage(UINT m, WPARAM w, LPARAM l) : message(m), wParam(w), lParam(l) {}
};
Vector<WinMessage> sgWinMessages;
#ifndef PBT_APMQUERYSUSPEND
#define PBT_APMQUERYSUSPEND 0x0000
#endif
//--------------------------------------
static LRESULT PASCAL WindowProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
switch ( message )
{
case WM_POWERBROADCAST:
{
if(wParam == PBT_APMQUERYSUSPEND)
return BROADCAST_QUERY_DENY;
return true;
}
case WM_ACTIVATEAPP:
if ((bool) wParam)
{
Video::reactivate();
ShowCursor(false);
if ( Video::isFullScreen() )
hideTheTaskbar();
// HACK: Windows 98 (after switching from fullscreen to windowed mode)
SetForegroundWindow( winState.appWindow );
}
else
{
Video::deactivate();
restoreTheTaskbar();
}
break;
case WM_SYSCOMMAND:
switch(wParam)
{
case SC_SCREENSAVE:
case SC_MONITORPOWER:
if(GetForegroundWindow() == winState.appWindow)
{
return 0;
}
break;
}
break;
case WM_ACTIVATE:
windowActive = LOWORD(wParam) != WA_INACTIVE;
if ( windowActive )
{
setMouseClipping(false/*TGE_Mouse*/);
windowNotActive = false;
Game->refreshWindow();
Input::activate();
}
else
{
setMouseClipping(false/*TGE_Mouse*/);
windowNotActive = true;
DInputManager* mgr = dynamic_cast<DInputManager*>( Input::getManager() );
if ( !mgr || !mgr->isMouseActive() )
{
// Deactivate all the mouse triggers:
for ( U32 i = 0; i < 3; i++ )
{
if ( mouseButtonState[i] )
mouseButtonEvent( SI_BREAK, KEY_BUTTON0 + i );
}
}
Input::deactivate();
}
break;
case WM_MOVE:
Game->refreshWindow();
break;
case MM_MCINOTIFY:
handleRedBookCallback(wParam, lParam);
break;
//case WM_DESTROY:
case WM_CLOSE:
PostQuitMessage(0);
break;
////////////////////////////////////////////////////////
/// IME
case WM_IME_SETCONTEXT:
if(g_pIME && g_pIME->OnWM_IME_SETCONTEXT())
return 0;
break;
case WM_INPUTLANGCHANGEREQUEST:
if(g_pIME && g_pIME->OnWM_INPUTLANGCHANGEREQUEST())
return 0;
break;
case WM_INPUTLANGCHANGE:
if(g_pIME && g_pIME->OnWM_INPUTLANGCHANGE((UWND) hWnd ))
return 0;
break;
case WM_IME_STARTCOMPOSITION:
if(g_pIME && g_pIME->OnWM_IME_STARTCOMPOSITION())
return 0;
break;
case WM_IME_ENDCOMPOSITION:
if(g_pIME && g_pIME->OnWM_IME_ENDCOMPOSITION())
return 0;
break;
case WM_IME_NOTIFY:
if(g_pIME && g_pIME->OnWM_IME_NOTIFY((UWND) hWnd, wParam ))
return 0;
break;
case WM_IME_COMPOSITION:
if(g_pIME && g_pIME->OnWM_IME_COMPOSITION( (UWND)hWnd, lParam ))
return 0;
break;
//IME End
//#ifdef UNICODE
// case WM_INPUTLANGCHANGE:
//// Con::printf("IME lang change");
// break;
//
// case WM_IME_SETCONTEXT:
//// Con::printf("IME set context");
// break;
//
// case WM_IME_COMPOSITION:
//// Con::printf("IME comp");
// break;
//
// case WM_IME_STARTCOMPOSITION:
//// Con::printf("IME start comp");
// break;
//#endif
default:
{
if (sgQueueEvents)
{
WinMessage msg(message,wParam,lParam);
sgWinMessages.push_front(msg);
}
}
}
return DefWindowProc(hWnd, message, wParam, lParam);
}
//--------------------------------------
static void OurDispatchMessages()
{
WinMessage msg(0,0,0);
UINT message;
WPARAM wParam;
LPARAM lParam;
DInputManager* mgr = dynamic_cast<DInputManager*>( Input::getManager() );
while (sgWinMessages.size())
{
msg = sgWinMessages.front();
sgWinMessages.pop_front();
message = msg.message;
wParam = msg.wParam;
lParam = msg.lParam;
if ( !mgr || !mgr->isMouseActive() )
{
switch ( message )
{
//#ifdef UNICODE
#if defined(TGE_RPG) || defined(UNICODE)
case WM_IME_COMPOSITION:
{
// Con::printf("OMG IME comp");
break;
}
case WM_IME_ENDCOMPOSITION:
{
// Con::printf("OMG IME end comp");
break;
}
case WM_IME_NOTIFY:
{
// Con::printf("OMG IME notify");
break;
}
case WM_IME_CHAR:
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -