C Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesC Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old November 22nd, 2012, 08:57 AM
HelpBot1 HelpBot1 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2012
Posts: 3 HelpBot1 Negative: is most likely a SPAMMER and a traitor to the cause. 
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?

Reply With Quote
  #2  
Old November 22nd, 2012, 08:19 PM
BobS0327 BobS0327 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2012
Posts: 118 BobS0327 User rank is Sergeant Major (2000 - 5000 Reputation Level)BobS0327 User rank is Sergeant Major (2000 - 5000 Reputation Level)BobS0327 User rank is Sergeant Major (2000 - 5000 Reputation Level)BobS0327 User rank is Sergeant Major (2000 - 5000 Reputation Level)BobS0327 User rank is Sergeant Major (2000 - 5000 Reputation Level)BobS0327 User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 3 Days 18 h 48 m 29 sec
Reputation Power: 44
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);
}


Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesC Programming > Disable key press

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap