[Common] Add support for KM_KBP_IT_EMIT_KEYSTROKE to allow the received key event to be passed on to the application

This commit is contained in:
Marc Durdin 2018-12-04 09:46:04 +11:00
parent 6354fef210
commit 8a2b55e58c
4 changed files with 18 additions and 17 deletions

View file

@ -143,10 +143,9 @@ json & operator << (json & j, km_kbp_action_item const &act)
j << km_kbp_context_item {act.type, {0,}, {act.character}}; // TODO: is act.type correct here? it may map okay but this is bad practice to mix constants across types. Similarly using act.character instead of act.type
break;
case KM_KBP_IT_BACK:
j << act.erased;
j << json::null; // act.erased;
break;
case KM_KBP_IT_PERSIST_OPT:
case KM_KBP_IT_RESET_OPT:
j << json::object
<< scope_names_lut[act.option->scope]
<< json::flat << json::object
@ -154,11 +153,6 @@ json & operator << (json & j, km_kbp_action_item const &act)
<< json::close
<< json::close;
break;
case KM_KBP_IT_VKEYDOWN:
case KM_KBP_IT_VKEYUP:
case KM_KBP_IT_VSHIFTDOWN:
case KM_KBP_IT_VSHIFTUP:
j << act.vkey;
break;
}
j << json::close;

View file

@ -68,10 +68,13 @@ namespace km {
_kmx.GetContext()->Set(ctxt.c_str());
_kmx.GetActions()->ResetQueue();
_kmx.ProcessEvent(state, vk, modifier_state);
state->actions.clear();
if (!_kmx.ProcessEvent(state, vk, modifier_state)) {
// We need to output the default keystroke
state->actions.emplace_back(km_kbp_action_item{ KM_KBP_IT_EMIT_KEYSTROKE, {0,}, {0} });
}
for (auto i = 0; i < _kmx.GetActions()->Length(); i++) {
auto a = _kmx.GetActions()->Get(i);
switch (a.ItemType) {
@ -127,6 +130,8 @@ namespace km {
break;
case QIT_INVALIDATECONTEXT:
// TODO: support invalidating the context
// TODO: IMPORTANT! invalidate the context; state->actions.emplace_back(km_kbp_action_item{ KM_KBP_IT_INVALIDATE_CONTEXT, {0,}, {0} });
break;
default:
//std::cout << "Unexpected item type " << a.ItemType << ", " << a.dwData << std::endl;
@ -136,7 +141,7 @@ namespace km {
state->actions.emplace_back(km_kbp_action_item{ KM_KBP_IT_END, {0,}, {0} });
return 0;
return KM_KBP_STATUS_OK;
}
constexpr km_kbp_attr const engine_attrs = {

View file

@ -110,7 +110,7 @@ extern const struct modifier_names s_modifier_names[];
extern KMX_BOOL g_debug_ToConsole, g_debug_KeymanLog, g_silent;
#ifdef _MSC_VER
#define DebugLog(msg,...) (ShouldDebug() ? DebugLog_1(__FILE__, __LINE__, __FUNCTION__, (msg),__VA_ARGS__) : 0)
#define DebugLog(msg,...) (km::kbp::kmx::ShouldDebug() ? km::kbp::kmx::DebugLog_1(__FILE__, __LINE__, __FUNCTION__, (msg),__VA_ARGS__) : 0)
#define console_error(msg,...) write_console(TRUE, (msg), __VA_ARGS__)
#define console_log(msg,...) write_console(FALSE, (msg), __VA_ARGS__)
#else

View file

@ -206,14 +206,15 @@ void apply_action(km_kbp_state const * state, km_kbp_action_item const & act, st
}
break;
case KM_KBP_IT_PERSIST_OPT:
case KM_KBP_IT_RESET_OPT:
assert(false); // TODO
break;
case KM_KBP_IT_VKEYDOWN:
case KM_KBP_IT_VKEYUP:
case KM_KBP_IT_VSHIFTDOWN:
case KM_KBP_IT_VSHIFTUP:
assert(false); // NOT SUPPORTED
/*
case KM_KBP_IT_INVALIDATE_CONTEXT:
assert(false); // TODO
break;
*/
case KM_KBP_IT_EMIT_KEYSTROKE:
std::cout << "action: emit keystroke" << std::endl;
break;
default:
assert(false); // NOT SUPPORTED
@ -296,6 +297,7 @@ int run_test(const std::string & file, const std::string & inputpath) {
// Run through key events, applying output for each event
for (auto p = next_key(keys); p.vk != 0; p = next_key(keys)) {
try_status(km_kbp_process_event(test_state, p.vk, p.modifier_state));
for (auto act = km_kbp_state_action_items(test_state, nullptr); act->type != KM_KBP_IT_END; act++) {
apply_action(test_state, *act, text_store);
}