2012-04-20 2 views
2

이 코드는 입력 버튼을 누른 후 사용자 유형을 인쇄합니다.사용자가 위로/아래로 화살표를 눌렀을 때의 이해

main() 
{ 

HANDLE   stdinInput = 0; 
DWORD   numEvents = 0; 
DWORD   numEventsRead = 0; 
DWORD   numReceivedRecords = 0; 
DWORD   fdwSaveOldMode; 
DWORD   fdwMode; 


char dataBuffer[100]; 
int bufferLen = 0; 


stdinInput = GetStdHandle(STD_INPUT_HANDLE); 

if (stdinInput == INVALID_HANDLE_VALUE) 
     perror("GetStdHandle"); 

if (! GetConsoleMode(stdinInput, &fdwSaveOldMode)) 
     perror("GetConsoleMode"); 

fdwMode = ENABLE_LINE_INPUT | ENABLE_ECHO_INPUT; 
if (! SetConsoleMode(stdinInput, fdwMode)) 
     perror("SetConsoleMode"); 


for(; ;) 
{ 


    GetNumberOfConsoleInputEvents(stdinInput, &numEvents); 

    if (numEvents != 0) { 

     INPUT_RECORD eventBuffer; 

     ReadConsoleInputA(stdinInput, &eventBuffer, 1, &numEventsRead); 


     if (eventBuffer.EventType == KEY_EVENT) { 

      if(eventBuffer.Event.KeyEvent.bKeyDown) 
      { 
       if(eventBuffer.Event.KeyEvent.uChar.UnicodeChar != 0) 
       { 
        printf("%c",eventBuffer.Event.KeyEvent.uChar.UnicodeChar); 
        dataBuffer[bufferLen++] = eventBuffer.Event.KeyEvent.uChar.UnicodeChar; 
        dataBuffer[bufferLen] = '\0';    

        if (dataBuffer[bufferLen] == 99 || eventBuffer.Event.KeyEvent.uChar.UnicodeChar == '\r') { 
        printf("User Wrote: %s\n",dataBuffer); 

        memset(dataBuffer,0,sizeof(dataBuffer)); 
        bufferLen = 0; 
        } 
       } 


      } 
     } 

    } 
} 

} 

지금 내가 그것을 사용자가 위/아래 화살표를 위로 누르면 감지하고 인쇄 할 수 있도록하려면 Enter 키를 누릅니다 필요없이 "위/아래 화살표를 누르면".

GetKeyState()와 함께 가상 키 코드를 사용하려고했지만 완료 할 수 없습니다.

이런 식으로 달성하는 방법에 대한 아이디어.

미리 감사드립니다.

답변

1

가상 키 코드에주의하십시오. 좋아요 :

+0

감사합니다. –

관련 문제