key activated script

This is a discussion on key activated script within the Windows Programming forums, part of the Platform Specific Boards category; How do I make a program detect which key is pressed, and depending on the key that's pressed it would ...

  1. #1
    Registered User Queatrix's Avatar
    Join Date
    Apr 2005
    Posts
    1,342

    Question key activated script

    How do I make a program detect which key is pressed, and depending on the key that's pressed it would execute specific script?

    For example, if you press 'h' the script 'Beep(2000,500);' would be activated - but if you press any other keys nothing would happen.

    Thanks in advance.

  2. #2
    *this
    Join Date
    Mar 2005
    Posts
    498
    Sorry if im wrong because im just starting, but since the CALLBACK function is used each time a key is pressed, cant you put a switch statement in the function to handle the letters you want, then each letter adds special things to a new message.

  3. #3
    Registered User Queatrix's Avatar
    Join Date
    Apr 2005
    Posts
    1,342
    I think I know what you're saying, but how would you do it?

  4. #4
    *this
    Join Date
    Mar 2005
    Posts
    498
    Well I was looking through some code, and I couldnt pin point it, sorry im still newbish at this, maybe someone who has more experties could answer this. Try a google search

  5. #5
    VA National Guard The Brain's Avatar
    Join Date
    May 2004
    Location
    Manassas, VA USA
    Posts
    903
    chapter #6 in petzold gives good examples on how to handle WM_CHAR and WM_KEYDOWN messages.
    Last edited by The Brain; 05-30-2005 at 12:38 PM.
    • "Problem Solving C++, The Object of Programming" -Walter Savitch
    • "Data Structures and Other Objects using C++" -Walter Savitch
    • "Assembly Language for Intel-Based Computers" -Kip Irvine
    • "Programming Windows, 5th edition" -Charles Petzold
    • "Visual C++ MFC Programming by Example" -John E. Swanke
    • "Network Programming Windows" -Jones/Ohlund
    • "Sams Teach Yourself Game Programming in 24 Hours" -Michael Morrison
    • "Mathmatics for 3D Game Programming & Computer Graphics" -Eric Lengyel

  6. #6
    Registered User
    Join Date
    Dec 2004
    Location
    The Netherlands
    Posts
    91

  7. #7
    Registered User Queatrix's Avatar
    Join Date
    Apr 2005
    Posts
    1,342
    Thanks, for you'r help guys, I don't know if this is the right way of doing it all I know is that this way works!

    Code:
    if(GetAsyncKeyState(VK_RIGHT)){ // If right arrow key is pressed...
    Beep(2000,300); }
    else{}

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 16
    Last Post: 11-23-2007, 01:48 PM
  2. Virtual keys
    By Arkanos in forum Windows Programming
    Replies: 4
    Last Post: 12-12-2005, 10:00 AM
  3. Directional Keys - Useing in Console
    By RoD in forum C++ Programming
    Replies: 38
    Last Post: 10-06-2002, 05:42 PM
  4. FAQ: Directional Keys - Useing in Console
    By RoD in forum FAQ Board
    Replies: 38
    Last Post: 10-06-2002, 05:42 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21