C++Builder Programming Forum
C++Builder  |  Delphi  |  FireMonkey  |  C/C++  |  Free Pascal  |  Firebird
볼랜드포럼 BorlandForum
 경고! 게시물 작성자의 사전 허락없는 메일주소 추출행위 절대 금지
C++빌더 포럼
Q & A
FAQ
팁&트릭
강좌/문서
자료실
컴포넌트/라이브러리
메신저 프로젝트
볼랜드포럼 홈
헤드라인 뉴스
IT 뉴스
공지사항
자유게시판
해피 브레이크
공동 프로젝트
구인/구직
회원 장터
건의사항
운영진 게시판
회원 메뉴
북마크
볼랜드포럼 광고 모집

C++빌더 Q&A
C++Builder Programming Q&A
[23061] Re:Re:Re:Re:Re:keypress 이벤트에서 한글키값을 읽을수 있는방법 알려주세요
유영인.Chris [cuperido] 2400 읽음    2002-12-06 13:01
안녕하세요.

제일 좋은 방법은, 입력 상태를 동기화 시키는 방법입니다. '가', '나' 이렇게 따로따로 글자를 처리해 주어서 찍어준다면, 왠만한 한글 입력기에서는 엉뚱한 반응을 일으킬 수 있습니다.

예를들어서, PC1에서 한글 상태로 토글이 되면, PC2에도 한글 상태로 토글을 하고, PC1에서 입력한 키를 그대로 PC2에서 한/영에 상관없이 찍는다면, 똑같은 키보드 루틴을 구현할 수 있습니다.

비슷한 루틴을 구현해 본 적이 있는데, 저의 경우에는 Serial 이 아닌, UTP 였습니다. 참고가 되셨으면 좋겠습니다. (WM_HINET 등의 키는 임의로 설정한 키 입니다. 키보드의 특수키의 값을 바꾸어서 사용하실 수 있습니다)


-=-=-=-=-=-= Header -=-=-=-=-=-=

//---------------------------------------------------------------------------

#ifndef Unit_RemoteH
#define Unit_RemoteH
//---------------------------------------------------------------------------
#include <Classes.hpp>
#include <Controls.hpp>
#include <StdCtrls.hpp>
#include <Forms.hpp>
#include <AppEvnts.hpp>
#include <ScktComp.hpp>
#include <Menus.hpp>
#include <NMUDP.hpp>
#include "CSPIN.h"
#include <ExtCtrls.hpp>

#define  ADMIN_PASSWORD                "hinet"
#define  MAX_RECEIVE_DATA              1000
#define  ACCELERATION                  2.5

#define  MAX_DIALOG                    9

#define  WM_HINET_QUIT                 WM_USER + 10
#define  WM_HINET_BACK                 WM_USER + 11
#define  WM_HINET_FORWARD              WM_USER + 12
#define  WM_HINET_REFRESH              WM_USER + 13
#define  WM_HINET_STOP                 WM_USER + 14
#define  WM_HINET_MAGNIFYING           WM_USER + 15
#define  WM_HINET_ZOOM                 WM_USER + 16
#define  WM_HINET_CLOSE                WM_USER + 17
#define  WM_HINET_TOP                  WM_USER + 18
#define  WM_HINET_BOTTOM               WM_USER + 19
#define  WM_HINET_LEFT                 WM_USER + 20
#define  WM_HINET_RIGHT                WM_USER + 21
#define  WM_HINET_NEW                  WM_USER + 22
#define  WM_HINET_MIDDLE               WM_USER + 23
#define  WM_HINET_ESCAPE               WM_USER + 24

#define  SPECIAL_KEY                   -32
#define  IDLE_LIMITED                  60


-=-=-=-=-=-= Source -=-=-=-=-=-=

/**************************************************************/
/* Hi-Net   Linux - Windows    Input Device Communicator      */
/*                                                            */
/*                                                  Cuperido  */
/**************************************************************/

#include <vcl.h>
#include <windows.h>
#include <string.h>
#include "Unit_Remote.h"

#pragma hdrstop
#pragma package(smart_init)
#pragma resource "*.dfm"


// Keyboard Virtual Code
// If value is plus, this mean is KEY_DOWN
// Otherwise, If value is minus, this mean is KEY_UP
unsigned char TableVirtualCode[128] =
              {000,

               VK_ESCAPE, 000, 000, 000, 000,
               000, 000, 000, 000, 000,
               000, 000, 000, VK_BACK, VK_TAB,
               000, 000, 000, 000, 000,

               000, 000, 000, 000, 000,
               000, 000, 000, VK_CONTROL, 000,
               000, 000, 000, 000, 000,
               000, 000, 000, 000, 000,

               000, VK_SHIFT, 000, 000, 000,
               000, 000, 000, 000, 000,
               000, 000, 000, VK_SHIFT, 000,
               VK_MENU, VK_SPACE, VK_CAPITAL, VK_F1, VK_F2,

               VK_F3, VK_F4, VK_F5, VK_F6, VK_F7,
               VK_F8, VK_F9, VK_F10, 000, 000,
               VK_HOME, VK_UP, VK_PRIOR, 000, VK_LEFT,
               000, VK_RIGHT, 000, VK_END, VK_DOWN,

               VK_NEXT, VK_INSERT, VK_DELETE, 000, 000,
               000, VK_F11, VK_F12, 000, 000,
               000, 000, 000, 000, 000,
               000, 000, 000, 000, 000,

               VK_HANGUL, 000, 000, 000, 000,
               000, 000, 000, 000, 000,
               000, 000, 000, VK_HANGUL, 000,
               000, 000, 000, 000, 000,

               000, 000, 000, 000, 000,
               000, 000};

// Keyboard Scan Code
char          TableScanCode[128] =
              {000,

                27,  49,  50,  51,  52,  53,  54,  55,  56,  57,
                48, 189, 187, 000, 000,  81,  87,  69,  82,  84,

                89,  85,  73,  79,  80, 219, 221,  13, 000,  65,
                83,  68,  70,  71,  72,  74,  75,  76, 186, 222,

               192, 000, 226,  90,  88,  67,  86,  66,  78,  77,
               188, 190, 191, 000, 000, 000,  32, 000, 000, 000,

               000, 000, 000, 000, 000, 000, 000, 000, 000, 000,
               000, 000, 000, 000, 000, 000, 000, 000, 000, 000,

               000, 000, 000, 000, 000, 000, 000, 000, 000, 000,
               000, 000, 000, 000, 000, 000, 000, 000, 000, 000,

               000, 000, 000, 000, 000, 000, 000, 000, 000, 000,
               000, 000, 000, 000, 000, 000, 000, 000, 000, 000,

               000, 000, 000, 000, 000, 000, 000};

TMain         *Main;
UINT          uiTrayMessage;
bool          blSituation, blCertification = false;
bool          blRightPress = false, blLeftPress = false;
bool          blSpecialKey = false;
HWND          hdHandle;
int           IDLE_TIME = 0;

/****************************************************************
Tmain
- Main Initialize
****************************************************************/
__fastcall TMain::TMain(TComponent* Owner) : TForm(Owner)
{

// Receive Register Message From Windows
uiTrayMessage = RegisterWindowMessage ("MyIconNotify");

}

/****************************************************************
AddTray
- Add icon to tray-bar
****************************************************************/
void __fastcall TMain::AddTray()
{

NOTIFYICONDATA   niIcon;

memset(&niIcon, 0x00, sizeof(niIcon));

niIcon.cbSize           = sizeof(niIcon);
niIcon.hWnd             = Handle;
strncpy(niIcon.szTip, "Hi-Net Communicator", sizeof(niIcon.szTip));

niIcon.hIcon            = Application->Icon->Handle;
niIcon.uCallbackMessage = WM_USER + 1;

niIcon.uFlags           = NIF_MESSAGE | NIF_ICON | NIF_TIP;

Shell_NotifyIcon(NIM_ADD, &niIcon);

}

/****************************************************************
RemoveTray
- Remove icon from tray-bar
****************************************************************/
void __fastcall TMain::RemoveTray()
{

NOTIFYICONDATA    niIcon;

memset(&niIcon, 0x00, sizeof(niIcon));

niIcon.cbSize     = sizeof(niIcon);
niIcon.hWnd       = Handle;

Shell_NotifyIcon(NIM_DELETE, &niIcon);

}

/****************************************************************
FormDestroy
- Destory processing
****************************************************************/
void __fastcall TMain::FormDestroy(TObject *Sender)
{

RemoveTray();

}

/****************************************************************
EventRestore
- Send SW_HIDE message to windows when windows was opened
****************************************************************/
void __fastcall TMain::EventRestore(TObject *Sender)
{

ShowWindow(Application->Handle, SW_HIDE);

}

/****************************************************************
MI_ExitClick
- Exit processing
****************************************************************/
void __fastcall TMain::MI_ExitClick(TObject *Sender)
{

// Disable close Event
Main->OnCloseQuery = NULL;

Main->Close();

}

/****************************************************************
TrayEvent
- Process tray-bar event
****************************************************************/
void __fastcall TMain::TrayEvent(TMessage &Msg)
{

POINT             P;

if(Msg.LParam == WM_LBUTTONDOWN)
   if(!blCertification) {
     // If doesn't certified not yet...
     if(PasswordCheck()) {
       // Input password, and turn to administrator mode.
       blCertification = true;
       ShowMessage("Administrator Mode");
     }

    } else {
     // If mode was administrator already.
     GetCursorPos(&P);
     SetForegroundWindow(Handle);
     Menu->Popup(P.x, P.y);

   }

}

/****************************************************************
FormCreate
- Form initialize event
****************************************************************/
void __fastcall TMain::FormCreate(TObject *Sender)
{

AddTray();

blSituation = True;

}

/****************************************************************
SituationCheck
- Process Enabled, Disabled button
****************************************************************/
void __fastcall TMain::SituationCheck()
{

if(blSituation) {
   MI_Enabled->Checked  = true;
   MI_Disabled->Checked = false;
  } else {
   MI_Enabled->Checked  = false;
   MI_Disabled->Checked = true;
}

}

/****************************************************************
MI_MessageClick
- Show message list box
****************************************************************/
void __fastcall TMain::MI_MessageClick(TObject *Sender)
{

if(blCertification) Main->Show();

}

/****************************************************************
FormCloseQuery
- Appear this event before form closing
****************************************************************/
void __fastcall TMain::FormCloseQuery(TObject *Sender, bool &CanClose)
{

// Ignore close message
Main->Hide();
CanClose = false;

}

/****************************************************************
BT_ClearClick
- Process clear message list box
****************************************************************/
void __fastcall TMain::BT_ClearClick(TObject *Sender)
{

Message->Lines->Clear();

}

/****************************************************************
MessageEnter
- Message list box could't have focus
****************************************************************/
void __fastcall TMain::MessageEnter(TObject *Sender)
{

BT_Clear->SetFocus();

}

/****************************************************************
MI_EnabledClick
- Turn to enable mode
****************************************************************/
void __fastcall TMain::MI_EnabledClick(TObject *Sender)
{

if(blCertification) {
   blSituation = true;
   SituationCheck();
}

}

/****************************************************************
MI_DisabledClick
- Turn to disable mode
****************************************************************/
void __fastcall TMain::MI_DisabledClick(TObject *Sender)
{

if(blCertification) {
   blSituation = false;
   SituationCheck();
}

}

/****************************************************************
PasswordCheck
- Input administrator password then return this agreement result
****************************************************************/
bool __fastcall TMain::PasswordCheck()
{

String            stPassword;


stPassword = InputBox("Hi-Net Communicator", "Please Input Administrator Password", "");
if(!strcmp(ADMIN_PASSWORD, stPassword.c_str())) return(true);
                                            else return(false);

}

/****************************************************************
MI_TurnClick      
- Turn to customer mode
****************************************************************/
void __fastcall TMain::MI_TurnClick(TObject *Sender)
{

blCertification = false;
ShowMessage("Customer Mode");

}

/****************************************************************
Communication_MouseDataReceived
- Appear this event when received data from 4444 port
****************************************************************/
void __fastcall TMain::Communication_MouseDataReceived(TComponent *Sender, int NumberBytes, AnsiString FromIP, int Port)
{

char              chReceiveData[MAX_RECEIVE_DATA];
int               itTail, itTemp;
POINT             lpPosition;


Communication_Mouse->ReadBuffer(chReceiveData, NumberBytes, itTail);
chReceiveData[itTail] = 0;

if(!blSituation) return;

if(blCertification) Message->Lines->Add (Format("Received mouse position data. [%d] Size", ARRAYOFCONST(( (int)itTail ))));

if(itTail == 3) {
   GetCursorPos(&lpPosition);

   if(blCertification) Message->Lines->Add (Format("> Present position - %d, %d", ARRAYOFCONST(( (int)lpPosition.x, (int)lpPosition.y ))));

   SetCursorPos(lpPosition.x + (chReceiveData[1] * ACCELERATION), lpPosition.y + (chReceiveData[2] * -1  * ACCELERATION));


   // 드래그 처리를 위한 루틴
   if(chReceiveData[0] & 1) {
     mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
     blLeftPress = true;
    } else {
     if(blLeftPress) {
       mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
       blLeftPress = false;
     }
   }

   // 브라우저 팝업 메뉴 때문에 잠시 보류
/*
   if(chReceiveData[0] & 2) {
     mouse_event(MOUSEEVENTF_RIGHTDOWN, 0, 0, 0, 0);
     blRightPress = true;
    } else {
     if(blRightPress) {
       mouse_event(MOUSEEVENTF_RIGHTUP, 0, 0, 0, 0);
       blRightPress = false;
     }
   }
*/

}

for(itTemp = 0; itTemp < itTail; itTemp ++)
   if(blCertification) Message->Lines->Add (Format("> Raw Data - %d", ARRAYOFCONST(( (signed int)chReceiveData[itTemp] ))));

if(blCertification) Message->Lines->Add (Format("> Acceleration - %d", ARRAYOFCONST(( (signed int)ACCELERATION ))));
if(blCertification) Message->Lines->Add ("");

}

/****************************************************************
Communication_KeyboardDataReceived
- Appear this event when received data from 4445 port
****************************************************************/
void __fastcall TMain::Communication_KeyboardDataReceived(TComponent *Sender, int NumberBytes, AnsiString FromIP, int Port)
{

char              chReceiveData[MAX_RECEIVE_DATA];
int               itTail, itTemp, itInput, itAssortment;
bool              blSkip = false;


Communication_Keyboard->ReadBuffer(chReceiveData, NumberBytes, itTail);

chReceiveData[itTail] = 0;
blSpecialKey          = false;


if(!blSituation) return;

if(blCertification) Message->Lines->Add (Format("Received keyboard signal data. [%d] Size", ARRAYOFCONST(( (int)itTail ))));

for(itTemp = 0; itTemp < itTail; itTemp ++) {
   if(blCertification) Message->Lines->Add (Format("> Raw Code - %d", ARRAYOFCONST(( (signed int)chReceiveData[itTemp] ))));

   itInput = (signed int)chReceiveData[itTemp];
   if(itInput < -127 || itInput > 127) itInput = 0;

   if(itInput > 0) {
     if(blCertification) Message->Lines->Add ("> Assortment - KEY_DOWN");
     blSkip = FunctionKey(blSpecialKey, true, itInput);
     itAssortment = 0;
    } else {
     // Special Key 체크
     if(itInput == SPECIAL_KEY) {
       if(blCertification) Message->Lines->Add ("> Special Key Inputed");
       blSpecialKey = true;

       continue;
     }

     if(blCertification) Message->Lines->Add ("> Assortment - KEY_UP");
     blSkip = FunctionKey(blSpecialKey, false, itInput);

     itAssortment = KEYEVENTF_KEYUP;
     itInput      = itInput ^ -128;
   }

   if(blCertification) Message->Lines->Add (Format("> Scan Code - %d", ARRAYOFCONST(( (signed int)TableScanCode[itInput] ))));
   if(blCertification) Message->Lines->Add (Format("> Virtual Code - %d", ARRAYOFCONST(( (signed int)TableVirtualCode[itInput] ))));


   if(!blSkip)
     if(TableVirtualCode[itInput])
       keybd_event(TableVirtualCode[itInput], 1, itAssortment, 0);
      else
       keybd_event(TableScanCode[itInput], TableScanCode[itInput], itAssortment, 0);

   blSpecialKey = false;
   blSkip       = false;
}

if(blCertification) Message->Lines->Add ("");

}

// 키 기능을 체크
bool __fastcall TMain::FunctionKey(bool blFunction, bool blKeyDown, int itScanCode)
{

bool              blSkip = false;


// Escape Key
if(blKeyDown && itScanCode == 1) {
   FindHandle();
   if(hdHandle) SendMessage(hdHandle, WM_HINET_ESCAPE, 0, 0);
}

// Stop Key
if(!blFunction && !blKeyDown && itScanCode == -25) {
   FindHandle();
   if(hdHandle) SendMessage(hdHandle, WM_HINET_STOP, 0, 0);
}

// Back Key
if(!blFunction && !blKeyDown && itScanCode == -26) {
   FindHandle();
   if(hdHandle) SendMessage(hdHandle, WM_HINET_BACK, 0, 0);
}

// Forward Key
if(blFunction && !blKeyDown && itScanCode == -26) {
   FindHandle();
   if(hdHandle) SendMessage(hdHandle, WM_HINET_FORWARD, 0, 0);
}

// Refresh Key
if(blFunction && !blKeyDown && itScanCode == -39) {
   FindHandle();
   if(hdHandle) SendMessage(hdHandle, WM_HINET_REFRESH, 0, 0);
}

// Magnifying Key
if(!blFunction && !blKeyDown && itScanCode == -34) {
   FindHandle();
   if(hdHandle) SendMessage(hdHandle, WM_HINET_MAGNIFYING, 0, 0);
}

// Zoom Key
if(blFunction && !blKeyDown && itScanCode == -66) {
   FindHandle();
   if(hdHandle) SendMessage(hdHandle, WM_HINET_ZOOM, 0, 0);
}

// NewWindows Key
if(blFunction && !blKeyDown && itScanCode == -67) {
   FindHandle();
   if(hdHandle) SendMessage(hdHandle, WM_HINET_NEW, 0, 0);
}

// CloseWindows Key
if(blFunction && !blKeyDown && itScanCode == -65) {
   FindHandle();
   if(hdHandle) SendMessage(hdHandle, WM_HINET_CLOSE, 0, 0);
}


if(blKeyDown && (itScanCode >= 2 && itScanCode <= 11)) {
   if(FindWindow("TKeyboard", NULL))
     switch(itScanCode) {
       case 3 : {
         blSkip = true;
         FindHandle();
         if(hdHandle) SendMessage(hdHandle, WM_HINET_TOP, 0, 0);
         break;
       }

       case 9 : {
         blSkip = true;
         FindHandle();
         if(hdHandle) SendMessage(hdHandle, WM_HINET_BOTTOM, 0, 0);
         break;
       }

       case 5 : {
         blSkip = true;
         FindHandle();
         if(hdHandle) SendMessage(hdHandle, WM_HINET_LEFT, 0, 0);
         break;
       }

       case 7 : {
         blSkip = true;
         FindHandle();
         if(hdHandle) SendMessage(hdHandle, WM_HINET_RIGHT, 0, 0);
         break;
       }

       case 6 : {
         blSkip = true;
         FindHandle();
         if(hdHandle) SendMessage(hdHandle, WM_HINET_MIDDLE, 0, 0);
         break;
       }
     }
}

return(blSkip);

}

void __fastcall TMain::FindHandle()
{

hdHandle = FindWindow("TTask", NULL);

}

/****************************************************************
MessageChange
- Message list box overflow check
****************************************************************/
void __fastcall TMain::MessageChange(TObject *Sender)
{

if(Message->Lines->Count > 1000)
   Message->Lines->Clear();

}

/****************************************************************
_btTestClick
- Key Test
****************************************************************/
void __fastcall TMain::_btTestClick(TObject *Sender)
{

int               itCode = _seTest->Value;

_edTest->SetFocus();
_edTest->SelStart = 1;

keybd_event(itCode, itCode, 0, 0);
keybd_event(itCode, itCode, KEYEVENTF_KEYUP, 0);

}

/****************************************************************
QuitMessage
- Quit Message
****************************************************************/
void __fastcall TMain::QuitMessage(TMessage &msg)
{

MI_ExitClick(NULL);

}

/****************************************************************
MI_ProtectClick
- Disable protect
****************************************************************/
void __fastcall TMain::MI_ProtectClick(TObject *Sender)
{                                                          

RECT              trCursorRect;


SystemParametersInfo(SPI_SCREENSAVERRUNNING, false, NULL, 0);
EnableWindow(FindWindowEx(FindWindow("Shell_TrayWnd", NULL), 0, "Button", NULL), true);
ShowWindow(FindWindow(NULL, "ShellTrayWnd"), SW_SHOW);

trCursorRect.left    = 0;
trCursorRect.top     = 0;
trCursorRect.right   = Screen->Width + 1;
trCursorRect.bottom  = Screen->Height + 1;

ClipCursor(&trCursorRect);

}

//---------------------------------------------------------------------------

void __fastcall TMain::SendClick(int X, int Y)
{

tagPOINT          tpPosition;


GetCursorPos(&tpPosition);

SetCursorPos(X, Y);
mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);

SetCursorPos(tpPosition.x, tpPosition.y);

}





홍석구 님이 쓰신 글 :
: 답변을 해주셔서 고맙습니다.
: 제가 작성하려고 하는 프로그램은
: PC 와 PC를 시리얼케이블로 연결하고 프로그램을 실행시킨후에
: 한쪽 PC에서 키보드를 입력하면 상태편 PC로 키보드 값을 시리얼통신을
: 통해서 보내주고 받은쪽에서 수신받은 키값을 보여주려고 합니다.
:
:     PC1 <--->  PC2
:  KEY입력  --> 화면에 같은 글자 출력
:  "가"입력 --> "가"출력

: 이렇게 처리하려고 합니다. 영문의 경우는 KEY값이 잘전송되나
: 한글은 전에 적은것처럼 KEY값을 잘찾지 못하고 있습니다.
: 한쪽 PC는 C++BUILDER로 프로그램을 작성하고 상대편PC는 자바로 프로그램을
: 작성하고 있습니다.
:
: 감사합니다.
:
:
:
: 유영인.Chris 님이 쓰신 글 :
: : 안녕하세요.
: :
: : 제가 질문을 신중하게 읽지 못해서 조금 실수를 하였네요.
: : 일단, 키 이벤트가 3개가 있는데, 각각 한글을 처리할때 조금씩 틀립니다.
: :
: : 1. OnKeyDown
: : 한글을 입력하면 VK_PROCESSKEY 라는 Key 값만 발생함
: :
: : 2. OnKeyPress
: : 한글 한자를 모두 입력시에만 발생. 흔히 입력을 하는 도중의 상황을 Caret 이라고 표현을 하는데, 이 상태에서는 표현되지 않습니다.
: :
: : 3. OnKeyUp
: : 한글 코드가 영문과 동일하게 키 값으로 바뀌어서 출력.
: :
: :
: : 가장 간단한 방법은, KeyUp 등에서 한글모드일때, 전의 문자를 비교하는 방법입니다.
: :
: : void __fastcall TForm1::Memo1KeyUp(TObject *Sender, WORD &Key, TShiftState Shift)
: : {
: :
: :  unsigned char     chChar;
: :
: :
: :  if(Memo1->SelStart <= 0) return;
: :  chChar = Memo1->Lines->Text[Memo1->SelStart];
: :
: :  if(chChar > 128) Label1->Caption = Memo1->Lines->Text.SubString(Memo1->SelStart - 1, 2);
: :              else Label1->Caption = (char)chChar;
: :
: : }
: :
: :
: : 물론, 다른 방식으로 처리를 하는 방법도 있습니다. 후킹이나 메세지 처리를 하는 방법입니다.
: : 어떤 작업을 하시려는지 알려주시면, 그에 가장 맞는 방법을 추천해 드리기가 더욱 쉬울것 같습니다.
: :
: :
: :
: : 홍석구 님이 쓰신 글 :
: : : 답변을 해주셔서 감사합니다.
: : : 그러면 Keypress 이벤트에서 파라미터로 넘어오는 char &Key 값은 무엇을 의미하는지요.
: : : 한글 입력 상태에서 메모 컴포넌트에서 "가"를 입력해서 Keypress 이벤트를 발생시키고
: : : 다시 "나"를 입력해서 Keypress 이벤트를 발생시키면
: : : 두글다 영문 'K' 한글 'ㅏ'가 마지막으로 입력되었는데 그러면 '가' 와 '나'를 구분할수 있는
: : : 방법은 없는지요.
: : :
: : : 제가 입력해서 확인해보니  
: : : 한글모드에서 '가' 입력시 Key 값은 0xB0  (176)
: : : 한글모드에서 '나' 입력시 Key 값은 0xB3  (179)
: : : 영문모드에서 K 입력시 Key 값은 0x4B  (75)
: : : 이렇게 Key값이 읽여집니다.
: : :
: : : 하지만 '가'라는 한글코드는 임프님이 쓰신것처럼 2Byte로 0xB0 0xA1
: : : '나' 는 '0xB3 0xAA 입니다.
: : :
: : : Keypress에서는 첫번째 바이트 값만 읽어오는데 2번째 바이트 값을 읽을 방법은 없는건지요.
: : :
: : : 개발환경
: : : Windows XP
: : : C++Builder 5.0 Enterprise
: : : Memo 컴포넌트 설정값
: : :     Font Charset HANGEUL_CHARSET
: : :     imeMode imDontCare
: : :     imeName 한국어 입력 시스템(IME 2000)
: : :
: : : 방법을 알고 있으시면 꼭 답변 부탁드립니다.
: : : 감사합니다.
: : :
: : :
: : : 유영인.Chris 님이 쓰신 글 :
: : : : 한글 코드가 꼭 따로 아스키 코드로 있는것은 아닙니다. 예를 들어, '하' 의 경우, KeyPress 가 2번 작동되겠지만, '늘' 의 경우에는 3번 작동됩니다.
: : : :
: : : : 따라서, 석구님께서 말씀하신대로 한글 코드가 2Byte 인것과는 KeyPress와는 상관이 없습니다. KeyPress에서는 눌려진 키 값을 반환해 줍니다. 이것은 편하게 그냥 키보드의 위치 값과 똑같다고 생각하시면 됩니다.
: : : :
: : : : 따라서, 'a' 와 'ㅁ' 의 경우 똑같은 아스키 값을 넘겨주게 됩니다. 다른 처리를 원하신다면, 한글 상태인지 영문 상태인지 알아본 다음, 처리를 따로 해주셔야 합니다
: : : :
: : : : 한글 영문 상태를 강제로 치환하는 방법은, 아래와 같이 처리하시면 됩니다.
: : : :
: : : :
: : : : HIMC              hiMode = ImmGetContext(Application->Handle);
: : : :
: : : : // 영문 자판
: : : : ImmSetConversionStatus(hiMode, IME_CMODE_ALPHANUMERIC, IME_CMODE_ALPHANUMERIC);
: : : : // 한글 자판
: : : : ImmSetConversionStatus(hiMode, IME_CMODE_HANGEUL, IME_CMODE_HANGEUL);
: : : :
: : : :
: : : :
: : : :
: : : :
: : : : 홍석구 님이 쓰신 글 :
: : : : : memo 컴포넌트에서 keypress 이벤트 등록했습니다.
: : : : : char로 넘어오는 키값을 한글에 대해서 읽을수 있나요.
: : : : : Q&A 찾아보고 Tip'N Tricks을 찾아봐도 keypress 이벤트에서
: : : : : 한글코드를 읽어오는 것은 못찾겠습니다.
: : : : : Tip'N Tricks에 임프님이 쓴글도 char [] 배열에 한글코드가 들어가 있는
: : : : : 데서 시작해서 sendmessage 하는 것인데 한글코드 자체를 읽어오지 못하니
: : : : :
: : : : : 아시는 분있으시면 꼭 답변 부탁합니다.
: : : : : c++builder 5.0
: : : : : windows xp 에서 개발하고 있습니다.
: : : : :
: : : : : void __fastcall TForm1::memoKeyKeyPress(TObject *Sender, char &Key)
: : : : : {
: : : : :     // Key 영문에 대해서는 작동하지만 한글코드는 알아내지 못하고 있습니다.
: : : : :     // 한글코드는 2byte인데 파라미터는 char로 넘어옵니다.
: : : : :     // 해결방법을 아시는 분이 계십니까
: : : : : }
: : : : :
: : : : : 감사합니다.

+ -

관련 글 리스트
23004 keypress 이벤트에서 한글키값을 읽을수 있는방법 알려주세요 홍석구 1242 2002/12/04
23009     Re:keypress 이벤트에서 한글키값을 읽을수 있는방법 알려주세요 유영인.Chris 1263 2002/12/04
23019         Re:Re:keypress 이벤트에서 한글키값을 읽을수 있는방법 알려주세요 홍석구 1346 2002/12/04
23043             Re:Re:Re:keypress 이벤트에서 한글키값을 읽을수 있는방법 알려주세요 유영인.Chris 3964 2002/12/05
23051                 Re:Re:Re:Re:keypress 이벤트에서 한글키값을 읽을수 있는방법 알려주세요 홍석구 1569 2002/12/06
23061                     Re:Re:Re:Re:Re:keypress 이벤트에서 한글키값을 읽을수 있는방법 알려주세요 유영인.Chris 2400 2002/12/06
Google
Copyright © 1999-2015, borlandforum.com. All right reserved.