The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.
|
 |
|
Dev Shed Forums
> Programming Languages
> C Programming
|
Disable key press
Discuss Disable key press in the C Programming forum on Dev Shed. Disable key press C programming forum discussing all C derivatives, including C#, C++, Object-C, and even plain old vanilla C. These languages are low level languages, and used on projects such as device drivers, compilers, and even whole computer operating systems.
|
|
 |
|
|
|
|

Dev Shed Forums Sponsor:
|
|
|

November 22nd, 2012, 08:57 AM
|
|
Registered User
|
|
Join Date: Nov 2012
Posts: 3
Time spent in forums: 49 m 22 sec
Reputation Power: 0
|
|
|
Disable key press
its not exactly how it sound.
i'm cheking if f1 is pressed with GetAsyncKeyState(VK_F1)
there is a way, after key is pressed, to set the press to zero? i mean if i make while that perm check for key pressed, after i press f1 it set f1 to non pressed?
|

November 22nd, 2012, 08:19 PM
|
|
|
Quote: there is a way, after key is pressed, to set the press to zero? i mean if i make while that perm check for key pressed, after i press f1 it set f1 to non pressed? |
You're using the wrong Win32 function. GetAsyncKeyState is essentially a keyboard polling method. What you need to use is a Windows hook mechanism. A Windows hook is mechanism that can be used to intercept events before they reach an application such as the F1 keyboard input.
But anyway, here is a code sample for using GetAsyncKeyState.
Code:
#pragma comment( lib, "user32.lib" )
#pragma comment( lib, "gdi32.lib" )
#include <windows.h>
#define VK_F1 0x70
#define WINDOW_CLASS_NAME "VIRTUALKEYDEMO"
LRESULT CALLBACK WindowProc(HWND hwnd,
UINT msg,
WPARAM wparam,
LPARAM lparam)
{
HDC hdc;
switch(msg)
{
case WM_DESTROY:
{
PostQuitMessage(0);
return(0);
}
break;
default:
break;
}
return (DefWindowProc(hwnd, msg, wparam, lparam));
}
int WINAPI WinMain( HINSTANCE hinstance,
HINSTANCE hprevinstance,
LPSTR lpcmdline,
int ncmdshow)
{
WNDCLASSEX winclass;
HWND hwnd;
MSG msg;
HDC hdc;
winclass.cbSize = sizeof(WNDCLASSEX);
winclass.style = CS_DBLCLKS | CS_OWNDC |
CS_HREDRAW | CS_VREDRAW;
winclass.lpfnWndProc = WindowProc;
winclass.cbClsExtra = 0;
winclass.cbWndExtra = 0;
winclass.hInstance = hinstance;
winclass.hIcon = LoadIcon(NULL, IDI_APPLICATION);
winclass.hCursor = LoadCursor(NULL, IDC_ARROW);
winclass.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
winclass.lpszMenuName = NULL;
winclass.lpszClassName = WINDOW_CLASS_NAME;
winclass.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
if (!RegisterClassEx(&winclass))
return(0);
if (!(hwnd = CreateWindowEx(NULL,
WINDOW_CLASS_NAME,
"Virtual Key Demo for press and release of F1 key",
WS_OVERLAPPEDWINDOW | WS_VISIBLE,
0,0,
400,100,
NULL,
NULL,
hinstance,
NULL)))
return(0);
while(TRUE)
{
if (PeekMessage(&msg,NULL,0,0,PM_REMOVE))
{
if (msg.message == WM_QUIT)
break;
TranslateMessage(&msg);
DispatchMessage(&msg);
}
hdc = GetDC(hwnd);
if(GetAsyncKeyState(VK_F1) & 0x8000)
TextOut(hdc, 0,16, "F1 key: Depressed", 18);
else
TextOut(hdc, 0,16, " ", 30);
ReleaseDC(hwnd, hdc);
}
return(msg.wParam);
}
|
Developer Shed Advertisers and Affiliates
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Rate This Thread |
Linear Mode
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|