-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
cbcd481
commit 8e81cca
Showing
4 changed files
with
36 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,35 @@ | ||
import Module from './module' | ||
import { getInputElement } from './focus' | ||
|
||
export function keyEvent(event: KeyboardEvent) { | ||
if (!getInputElement()) { | ||
return | ||
} | ||
const isRelease = event.type === 'keyup' | ||
function extract(event: KeyboardEvent): [string, string, number] | undefined { | ||
const { key, code, shiftKey, altKey, ctrlKey, metaKey } = event | ||
// Host IME | ||
if (key === 'Process') { | ||
return | ||
return undefined | ||
} | ||
const capsLock = event.getModifierState('CapsLock') | ||
const modifiers = Number(shiftKey) | Number(capsLock) << 1 | Number(ctrlKey) << 2 | Number(altKey) << 3 | Number(metaKey) << 6 | ||
if (Module.ccall('process_key', 'bool', ['string', 'string', 'number', 'bool'], [key, code, modifiers, isRelease])) { | ||
return [key, code, modifiers] | ||
} | ||
|
||
export function keyEvent(event: KeyboardEvent) { | ||
if (!getInputElement()) { | ||
return | ||
} | ||
const extracted = extract(event) | ||
if (!extracted) { | ||
return | ||
} | ||
const isRelease = event.type === 'keyup' | ||
if (Module.ccall('process_key', 'bool', ['string', 'string', 'number', 'bool'], [...extracted, isRelease])) { | ||
event.preventDefault() | ||
} | ||
} | ||
|
||
export function jsKeyToFcitxString(event: KeyboardEvent) { | ||
const extracted = extract(event) | ||
if (!extracted) { | ||
return '' | ||
} | ||
return Module.ccall('js_key_to_fcitx_string', 'string', ['string', 'string', 'number'], extracted) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters