Skip to content

Commit

Permalink
Fix bug in key state detection and fix bugs in Capslock and Shift key…
Browse files Browse the repository at this point in the history
… handling.
  • Loading branch information
PCMan authored and PCMan committed Sep 19, 2013
1 parent 160c1b5 commit 1830c6c
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 5 deletions.
8 changes: 5 additions & 3 deletions ChewingTextService/ChewingTextService.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -190,12 +190,14 @@ bool TextService::onKeyDown(Ime::KeyEvent& keyEvent, Ime::EditSession* session)

UINT charCode = keyEvent.charCode();
if(charCode && isprint(charCode)) { // printable characters (exclude extended keys?)
langMode_ = ::chewing_get_ChiEngMode(chewingContext_);

int oldLangMode = ::chewing_get_ChiEngMode(chewingContext_);
bool temporaryEnglishMode = false;
// If Caps lock is on, temporarily change to English mode
if(cfg.enableCapsLock && keyEvent.isKeyToggled(VK_CAPITAL))
temporaryEnglishMode = true;
// If Shift is pressed, but we don't want to enter full shape symbols
if(!cfg.fullShapeSymbols && keyEvent.isKeyDown(VK_SHIFT))
temporaryEnglishMode = true;

if(langMode_ == SYMBOL_MODE) { // English mode
::chewing_handle_Default(chewingContext_, charCode);
Expand All @@ -208,7 +210,7 @@ bool TextService::onKeyDown(Ime::KeyEvent& keyEvent, Ime::EditSession* session)
charCode = isupper(charCode) ? tolower(charCode) : toupper(charCode);
}
::chewing_handle_Default(chewingContext_, charCode);
::chewing_set_ChiEngMode(chewingContext_, langMode_); // restore previous mode
::chewing_set_ChiEngMode(chewingContext_, oldLangMode); // restore previous mode
}
else { // Chinese mode
if(isalpha(charCode)) // alphabets: A-Z
Expand Down
Binary file modified ChewingTextService/ChewingTextService.rc
Binary file not shown.
4 changes: 2 additions & 2 deletions libIME/KeyEvent.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ class KeyEvent {
}

bool isKeyDown(UINT code) const {
return (keyStates_[code] & (1 << 8)) != 0;
return (keyStates_[code] & (1 << 7)) != 0;
}

bool isKeyToggled(UINT code) const {
Expand Down Expand Up @@ -98,7 +98,7 @@ class KeyState {
}

bool isDown() {
return ((state_ & (1 << 16)) != 0);
return ((state_ & (1 << 15)) != 0);
}

bool isToggled() {
Expand Down

0 comments on commit 1830c6c

Please sign in to comment.