📄 input.cpp
字号:
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
//
// Use of this sample source code is subject to the terms of the Microsoft
// license agreement under which you licensed this sample source code. If
// you did not accept the terms of the license agreement, you are not
// authorized to use this sample source code. For the terms of the license,
// please see the license agreement between you and Microsoft or, if applicable,
// see the LICENSE.RTF on your install media or the root of your tools installation.
// THE SAMPLE SOURCE CODE IS PROVIDED "AS IS", WITH NO WARRANTIES.
//
#include "Input.hpp"
#include "MultiTap.h"
#include "SoftKeybd.h"
#include <winuserm.h>
/*------------------------------------------------------------------------------
Input_Initialize
Allows the input library to initialize internal controls/state -
Returns: HRESULT indicating success or failure. FAILURE indicates the app
could not start properly and must shutdown
------------------------------------------------------------------------------*/
HRESULT
Input_Initialize(
__in RECT* pDefaultScreen
)
{
HRESULT hr;
hr = Multitap_Initialize();
ASSERT(SUCCEEDED(hr) || (hr == HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND)));
hr = SoftKeybd_Initialize(pDefaultScreen);
return hr;
}
/*------------------------------------------------------------------------------
Input_Uninitialize
Allows the input library to uninitialize and cleanup any allocated memory/state
------------------------------------------------------------------------------*/
HRESULT
Input_Uninitialize(
)
{
HRESULT hr = S_OK;
return hr;
}
/*------------------------------------------------------------------------------
Input_GetIMEType
Determines the currently active IME type
------------------------------------------------------------------------------*/
Input_t::IMEType_e
Input_GetIMEType(
void
)
{
return Multitap_GetActiveIMEType();
}
/*------------------------------------------------------------------------------
Input_GetInputPanelTop
Get the top position of current Input panel
------------------------------------------------------------------------------*/
int
Input_GetInputPanelTop(
void
)
{
return SoftKeybd_GetTop();
}
/*------------------------------------------------------------------------------
Input_HandleEvent
Indicates that there is an event the input library may want to handle -
return value is ignored
Parameters:
event: The event that occurred
param: The IPARAM associated with that event
------------------------------------------------------------------------------*/
HRESULT
Input_HandleEvent(
Input_t::InputEvent_e event,
Input_t::IPARAM param
)
{
HRESULT hr;
switch(event)
{
case Input_t::ieEditControlGainFocus: // IPARAM = HWND that gained focus
Multitap_SetFocusedEditCtrl(reinterpret_cast<HWND>(param));
return SoftKeybd_SetFocusedEditCtrl(reinterpret_cast<HWND>(param));
case Input_t::ieEditControlLostFocus: // IPARAM = HWND that lost focus
return SoftKeybd_KillFocusedEditCtrl();
case Input_t::ieInsertSymbol:
return Multitap_InsertSymbol(reinterpret_cast<WCHAR>(param));
case Input_t::ieWMSettingChanged:
hr = SoftKeybd_OnSettingChange(reinterpret_cast<WPARAM>(param));
if (SoftKeybd_IsVisible())
{
Multitap_SetActiveIMEType(Input_t::itNum);
}
return hr;
case Input_t::ieChangeInputPanelStatus:
return SoftKeybd_ChangeSIPStatus(reinterpret_cast<BOOL>(param));
default:
return S_FALSE;
}
}
/*------------------------------------------------------------------------------
Input_HideInputPanel
Force the input panel to hide
------------------------------------------------------------------------------*/
HRESULT
Input_HideInputPanel(
void
)
{
SoftKeybd_ShowHide(FALSE);
return S_OK;
}
/*------------------------------------------------------------------------------
Input_IsIMEEnabled
Determine whether the phone IME is enabled or not
------------------------------------------------------------------------------*/
BOOL
Input_IsIMEEnabled(
void
)
{
return Multitap_IsEnabled();
}
/*------------------------------------------------------------------------------
Input_IsInputPanelEnabled
Determine whether the Input panel is enabled or not
------------------------------------------------------------------------------*/
BOOL
Input_IsInputPanelEnabled(
void
)
{
return SoftKeybd_IsEnabled();
}
/*------------------------------------------------------------------------------
Input_IsInputPanelVisible
Determine whether the Input panel is visible on the screen or not
------------------------------------------------------------------------------*/
BOOL
Input_IsInputPanelVisible(
void
)
{
return SoftKeybd_IsVisible();
}
/*------------------------------------------------------------------------------
Input_SetIMEType
Sets the active IME type
------------------------------------------------------------------------------*/
HRESULT
Input_SetIMEType(
Input_t::IMEType_e type
)
{
SoftKeybd_ShowHide(FALSE, TRUE);
return Multitap_SetActiveIMEType(type);
}
/*------------------------------------------------------------------------------
Input_SetInputMode
Allows an edit control to request a specific IME mode if this input
library provides this service.
Parameters:
Control: The control to set IME mode for
InputMode: The requested new mode
------------------------------------------------------------------------------*/
HRESULT
Input_SetInputMode(
HWND Control,
DWORD InputMode
)
{
return Multitap_SetInputMode(Control, InputMode);
}
/*------------------------------------------------------------------------------
Input_ShouldDispatchHotkey
Handles a hotkey (KEYDOWN) event concerning * or # hotkeys. Input lib is free to
modify the value that will be dispatched (e.g. instead of # dispatch a
space character). Return value indicates whether the key should be dispatched
or eaten
Parameters:
id: The identifier of the hotkey
pCharacterToDispatch: OUT param - the value of the character to be dispatched
Returns (BOOL): TRUE if the outparam should be dispatched, FALSE otherwise
------------------------------------------------------------------------------*/
BOOL
Input_ShouldDispatchHotkey(
Input_t::HotKeyId_e id,
__out WCHAR* pCharacterToDispatch
)
{
return Multitap_ShouldDispatchHotkey(id, pCharacterToDispatch);
}
/*------------------------------------------------------------------------------
Input_ShouldDispatchKey
Function that allows the library to eat a keydown event before the event is passed to
an edit control
Parameters:
VirtualKey: The virtual keycode of the key
Returns (BOOL): TRUE - the keycode can passthrough to the control,
FALSE - the keycode should be eaten
------------------------------------------------------------------------------*/
BOOL
Input_ShouldDispatchKey(
UINT VirtualKey
)
{
BOOL Dispatch = FALSE;
switch(VirtualKey)
{
case VK_TAB:
// if it is TAB, we simuate either VK_DOWN or VK_UP according to
// the shift key status, by sending the message to the focused control
SendMessage(
GetFocus(),
WM_KEYDOWN,
GetKeyState(VK_SHIFT) < 0 ? (WPARAM) VK_UP : (WPARAM)VK_DOWN,
0
);
break;
default:
Dispatch = TRUE;
break;
}
return Dispatch;
}
/*------------------------------------------------------------------------------
Input_ShowInputPanel
Force the input panel to show
------------------------------------------------------------------------------*/
HRESULT
Input_ShowInputPanel(
void
)
{
SoftKeybd_ShowHide(TRUE);
return S_OK;
}
/*------------------------------------------------------------------------------
Input_ToggleInputPanel
Toggle the input panel
------------------------------------------------------------------------------*/
HRESULT
Input_ToggleInputPanel(
void
)
{
// Switch on/off the input panel according to the current input panel status
// Note: if OEM doesn't have SIP soft button on screen, they can
// turn on/off the Sip outside of the app, and it will work as well
SoftKeybd_ShowHide(!SoftKeybd_IsVisible(), TRUE);
return S_OK;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -