Skip to content

Commit

Permalink
Merge pull request #2 from lewtds/master
Browse files Browse the repository at this point in the history
More major features implemented
  • Loading branch information
Trung Ngo committed Jan 27, 2014
2 parents 57cc10a + 811bf02 commit 7523fd7
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 11 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Một số trang cần xem:

https://github.com/BoGoEngine/bogo-win32/wiki/Facts-&-Decisions

## Hướng dẫn cài đặt
## Hướng dẫn cài đặt từ mã nguồn

Cài dependency:

Expand All @@ -29,7 +29,7 @@ Build file DLL:

Đăng ký file DLL (cần quyền Administrator):

regsvr32 dist\testComServer.dll
regsvr32 dist\bogo.dll

BoGo sẽ hiện ra trong danh sách các input method:

Expand Down
52 changes: 44 additions & 8 deletions bogo_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,12 @@
TF_ES_READWRITE = 0x6
TF_ES_ASYNC = 0x8

WM_CHAR = 0x0102
VK_BACK = 0x08
VK_SPACE = 0x20
WM_CHAR = 0x0102

VK_BACK = 0x08
VK_CONTROL = 0x11
VK_MENU = 0x12
VK_SPACE = 0x20

serverGUIDPointer = ctypes.pointer(GUID("{4581A23E-03EA-4614-975B-FF6206A8B840}"))

Expand Down Expand Up @@ -108,6 +111,7 @@ def Activate(self, thread_manager, client_id):
logging.debug("Activated")

self.client_id = client_id
self.thread_manager = thread_manager

keystroke_manager = thread_manager.QueryInterface(ITfKeystrokeMgr)
keystroke_manager.AdviseKeyEventSink(client_id, self, True)
Expand All @@ -116,6 +120,10 @@ def Activate(self, thread_manager, client_id):

def Deactivate(self):
logging.debug("Deactivated")

keystroke_manager = self.thread_manager.QueryInterface(ITfKeystrokeMgr)
keystroke_manager.UnadviseKeyEventSink(self.client_id)

self.reset()

#
Expand All @@ -138,15 +146,43 @@ def OnTestKeyDown(self, this, input_context, virtual_key_code, key_info, out_eat
return

if virtual_key_code == VK_BACK:
self.raw_string = self.raw_string[:-1]
self.old_string = self.old_string[:-1]
if self.old_string == "":
self.reset()
# Logic copied from ibus-bogo
if self.old_string != "":
deleted_char = self.old_string[-1]
self.old_string = self.old_string[:-1]
self.raw_string = self.raw_string[:-1]

if len(self.old_string) == 0:
self.reset()
else:
index = self.raw_string.rfind(deleted_char)
self.raw_string = self.raw_string[:-2] if index < 0 else \
self.raw_string[:index] + \
self.raw_string[(index + 1):]
out_eaten[0] = False
return

if self.we_will_eat(virtual_key_code):
new_string, raw_string = bogo.process_key(self.old_string, chr(virtual_key_code))

# FIXME: Refactor the ToAscii code to a function/method
keyboard_state = (ctypes.c_ubyte * 256)()

if ctypes.windll.user32.GetKeyboardState(keyboard_state) is False:
error = ctypes.windll.kernel32.GetLastError()
logging.debug("GetKeyboardState() Error: %x", error)

scan_code = (key_info >> 16) & 0xFF
buff = ctypes.create_string_buffer(2)
output = ctypes.windll.user32.ToAscii(virtual_key_code, scan_code, keyboard_state, buff, 0)

logging.debug("ToAscii() - %s - %s", output, buff.value)
logging.debug("CTRL: %s ALT: %s", keyboard_state[VK_CONTROL], keyboard_state[VK_MENU])

if keyboard_state[VK_MENU] or keyboard_state[VK_CONTROL]:
out_eaten[0] = False
return

new_string, raw_string = bogo.process_key(self.old_string, buff.value, self.raw_string)

same_initial_chars = list(takewhile(unicode.__eq__, zip(self.old_string, self.new_string)))
n_backspace = len(self.old_string) - len(same_initial_chars)
Expand Down
7 changes: 6 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,15 @@
BoGo = dict(
modules = ["bogo_server"],
other_resources = [("TYPELIB", 1, file(r"interfaces\\bogo.tlb", "rb").read())],
dest_base = r"testComServer"
dest_base = r"bogo",
create_exe = False
)

setup(name="BoGo",
version="0.1.0",
author="Trung Ngo",
author_email="[email protected]",
ctypes_com_server = [BoGo],
zipfile=None,
options={"py2exe": {"bundle_files": 3, "dll_excludes": ["w9xpopen.exe"]}},
)

0 comments on commit 7523fd7

Please sign in to comment.