[MFC] Ctrl 과 Shift 클릭여부

다음과 같이 간단하게 사용할수 있다.

#define IsSHIFTpressed() ( (GetKeyState(VK_SHIFT) & (1 << (sizeof(SHORT)*8-1))) != 0   )
#define IsCTRLpressed()  ( (GetKeyState(VK_CONTROL) & (1 << (sizeof(SHORT)*8-1))) != 0 )


GetKeyState() Return Value

The return value specifies the status of the specified virtual key, as follows:

  • If the high-order bit is 1, the key is down; otherwise, it is up.
  • If the low-order bit is 1, the key is toggled. A key, such as the CAPS LOCK key, is toggled if it is turned on. The key is off and untoggled if the low-order bit is 0. A toggle key's indicator light (if any) on the keyboard will be on when the key is toggled, and off when the key is untoggled.


그동안 이런경우.. Ctrl이 눌리면 멤버 Bool값을 true로하여 그값과 조합으로 Ctrl+c 같은 키 이벤트를 처리했었다..
모르면 몸이 피곤하다.

by 이카로스 | 2009/03/03 12:53 | C++/MFC | 트랙백 | 덧글(2)

트랙백 주소 : http://icarosss.egloos.com/tb/2250787
☞ 내 이글루에 이 글과 관련된 글 쓰기 (트랙백 보내기) [도움말]
Commented by 우하하 at 2009/03/03 13:09
더 간단하게 이렇게 할 수도 있어요.
BOOL bControlKey = (0x8000 == (0x8000 & GetKeyState(VK_CONTROL)));
BOOL bShiftKey = (0x8000 == (0x8000 & GetKeyState(VK_SHIFT)));
복잡하게 쉬프트연산 안쓰셔도 됩니다.
Commented by 이카로스 at 2009/03/03 13:28
아 그렇군요 감사합니다^^;
수학은 예전엔 잘했다고 생각했는데 영 안되네요 ㅎ

:         :

:

비공개 덧글

.

<< 이전 페이지     다음 페이지 >>