가상키보드 후킹문제...한글입력이 ㄱ ㅏ ㄹ 이런식..
마디
dotum
#pragma data_seg(shardata)
static hwnd hwndmain = null;
static hwnd hwndmainfrm = null;
static hinstance hinstance;
static hwnd hwndprevfocused = null;
static hwnd hwndprevforeground = null;
static hwnd hwndprevfocusedmainfrm = null;
#pragma data_seg()
hhook myhhookmouse, myhhookkeyboard, myhhookcbt, myhhookcallwndproc;
hwnd hwndtempforeground, hwndtempfocused;
char str[100];
static bool iseng = true;
#define wm_keyboardclicked wm_user + 10
#define wm_ime_state_eng wm_user + 11
#define wm_ime_state_han wm_user + 12
int far pascal initkeyboarddll(hwnd hmain, hwnd hwndmainfrm);
int far pascal installhook();
int far pascal showkeyboard();
int far pascal uninstallhook();
int far pascal hidekeyboard();
lresult callback mymousehookingproc(int ncode, wparam wparam, lparam lparam);
lresult callback mykeyboardhookingproc(int ncode, wparam wparam, lparam lparam);
lresult callback mycallwndproc(int ncode, wparam wparam, lparam lparam);int far pascal initkeyboarddll(hwnd hmain, hwnd hwndmainfrm)
{
cstring strmyclass;
hinstance = theapp.m_hinstance;
rect keyboardrect = {100, 100, 700, 400};
strmyclass = afxregisterwndclass(
cs_vredraw | cs_hredraw,
loadcursor(null, idc_arrow),
(hbrush) getstockobject(white_brush),
0);
myckeywnd.createex(0, strmyclass, mywnd,
ws_popup|ws_visible|ws_ex_topmost, crect(12,473,809,681), cwnd::fromhandle(hmain), null);
setwindowpos(myckeywnd.m_hwnd, hwnd_topmost, 12, 473, 797, 208, swp_noactivate | swp_hidewindow);
myckeywnd.m_fiseng = iseng;
hwndmain = myckeywnd.m_hwnd;
hwndmainfrm = myckeywnd.m_hwnd;
return 1;
}
int far pascal installhook()
{
myhhookcallwndproc = setwindowshookex(wh_callwndproc, (hookproc)mycallwndproc, hinstance, 0);
myhhookmouse = setwindowshookex(wh_mouse, (hookproc)mymousehookingproc, hinstance, 0);
myhhookkeyboard = setwindowshookex(wh_keyboard, (hookproc)mykeyboardhookingproc, hinstance, 0);
return 1;
}
int far pascal uninstallhook()
{
//if(myhhookcallwndproc) unhookwindowshookex(myhhookcallwndproc);
if(myhhookmouse) unhookwindowshookex(myhhookmouse);
if(myhhookkeyboard) unhookwindowshookex(myhhookkeyboard);
if(myhhookcbt) unhookwindowshookex(myhhookcbt);
if(myhhookcallwndproc) unhookwindowshookex(myhhookcallwndproc);
return 1;
}
lresult callback mycallwndproc(int ncode, wparam wparam, lparam lparam)
{
lppoint lpcurpos = new point;
rect wndrect;
pcwpstruct pparamstruct;
pparamstruct = (pcwpstruct)lparam;
if(ncode 0)
{
if(pparamstruct-message == wm_activate)
{
if(getcursorpos(lpcurpos)) //현재 커서의 위치를 구해서
{
if(getwindowrect(hwndmain, &wndrect)) // 현재 키보드의 영역안에 커서가 있으면
{
if(ptinrect(&wndrect, *lpcurpos))
{
// sleep(1);
setforegroundwindow((hwnd)pparamstruct-wparam);
return true;
}
}
}
}
}
return callnexthookex(myhhookcallwndproc, ncode, wparam, lparam);
}lresult callback mymousehookingproc(int ncode, wparam wparam, lparam lparam)
{
if(ncode=0)
{
if(wparam == wm_lbuttondown)//왼쪽 클릭된 위치가 키보드의 화면이면 사용자 메세지를 키보드프로그램으로 보내고 아니면 그냥 통과
{
if(((lpmousehookstruct)lparam)-hwnd == hwndmain) // 키보드윈도우의 핸들과 같으면
{
if(getforegroundwindow() != hwndprevforeground && hwndprevfocused)
{
setforegroundwindow(hwndprevforeground);
if(getfocus() != hwndprevfocused && hwndprevfocused)
setfocus(hwndprevfocused);
}
postmessage(hwndmain, wm_keydown, (wparam)lparam, (lparam)hwndprevforeground);
sleep(300);
return true;
}
else if(((lpmousehookstruct)lparam)-hwnd)
{
}
}
else if(wparam == wm_lbuttonup)
p;{
if(((lpmousehookstruct)lparam)-hwnd != hwndmain && ((lpmousehookstruct)lparam)-hwnd)
{
hwndtempforeground = getforegroundwindow();
hwndtempfocused = getfocus();
if(!hwndtempforeground || hwndtempforeground == hwndprevforeground)
hwndtempforeground = getforegroundwindow();
if(!hwndtempfocused || hwndtempfocused == hwndprevfocused)
hwndtempfocused = getfocus();
hwndprevfocused = hwndtempfocused;
hwndprevforeground = hwndtempforeground;
}
}
}
return callnexthookex(myhhookmouse, ncode, wparam, lparam);
}
lresult callback mykeyboardhookingproc(int ncode, wparam wparam, lparam lparam)
{
lppoint lpcurpos = new point;
//rect wndrect;
if(ncode == hc_action)
{
if((wparam == 229 && lparam == -2147483647)||(wparam == 229 && lparam == -2147483648.0))
{
return true;
}
}
return callnexthookex(myhhookkeyboard, ncode, wparam, lparam);
}
이런식으로 후킹하는 걸 인터넷 소스 참고했는데...
한글입력시 ㄱ ㅏ ㄴ 이런식으로 조합이 안됩니다. 포커스 문제라는거같은데...어떻게 해야할까요?