Thread: keybd_event() problems

  1. #1
    Registered User
    Join Date
    Jun 2002
    Posts
    9

    keybd_event() problems

    hello all, i am creating a simple macro program and have stumbled uppon a few small problems...

    number 1, i can emulate special chars such as '/' (VK_SLASH)

    i have tried a number of ways to fix this buy cant get it working,

    VK_SLASH returns as an undeclared identifier so i have tried:

    keybd_event('/',0,0,0);

    and have also tried above with a toupper(), and also with a vk_shift before it, cant get it to work tho

    my second problem, is i cant figure out how to press and hold a key with code.

    i have tried:
    Code:
    keybd_event(key,0,0,0);
    Sleep(10000);
    keybd_event(key, 0, KEYEVENTF_KEYUP, 0);
    but that only presses the key once then waits 10 sec then moves on.

    i have tried it in a for loop too
    Code:
    for(int i=0; i<10000; i++)
    {
    keybd_event(key,0,0,0);
    }
    keybd_event(key, 0, KEYEVENTF_KEYUP, 0);
    
    and also:
    
    for(int i=0; i<10000; i++)
    {
    keybd_event(key,0,0,0);
    keybd_event(key, 0, KEYEVENTF_KEYUP, 0);
    }
    (trying every possible solution)
    all that does is press the key 10,000 times super fast, its not the same as holding it down. technically i could be the same as holding it down as far as text programs are concerned, but all it causes are freezes/slowdown in graphical hands free presentations.

    thx in advance for any light shed on my problem.

  2. #2
    It's full of stars adrianxw's Avatar
    Join Date
    Aug 2001
    Posts
    4,829
    Part 6 of my console tutorial, here, contains some advice on the use of the keybd_event() function.

    You'll notice the example I use presses and holds the Alt key while the Enter key is pressed, then releases them.

    You might want to investigate the scan code. MSDN says it is not required, however, I have found keybd_event() does not always work without the correct scan code.
    Wave upon wave of demented avengers march cheerfully out of obscurity unto the dream.

  3. #3
    Registered User
    Join Date
    Jun 2002
    Posts
    9
    i actually found your site on google the other day hehe, im going to check out google for a scan code list.

  4. #4
    Registered User
    Join Date
    Jun 2002
    Posts
    9
    well, found scan code, tried scan code... and no dice,

    tried
    Code:
    	keybd_event('/', 0x35, 0, 0);
    	keybd_event('/', 0x35, KEYEVENTF_KEYUP, 0);
    and also tried
    Code:
    	keybd_event(VK_SLASH, 0x35, 0, 0);
    	keybd_event(VK_SLASH, 0x35, KEYEVENTF_KEYUP, 0);
    which still gives an undeclared identifier.

  5. #5
    It's full of stars adrianxw's Avatar
    Join Date
    Aug 2001
    Posts
    4,829
    Try using the code VK_OEM_2 what I'm wondering about is the language settings. You see the position of keys is fixed but the character represented by the keypress is interpretted by the keyboard driver. On a UK keyboard, the '/' character is with the '?' character on the key near the right Shift key, but on my Danish keyboard it is Shift-7 for example.

    VK_SLASH is not defined, so would not work.

    I would not necessarily trust a table of scan codes unless you have one for your specific language setting. There is a program in part 6 of my tutorial that will return the scan codes from your keyboard with your settings.
    Wave upon wave of demented avengers march cheerfully out of obscurity unto the dream.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. No clue how to make a code to solve problems!
    By ctnzn in forum C Programming
    Replies: 8
    Last Post: 10-16-2008, 02:59 AM
  2. C Pointers Problems
    By mhelal in forum C Programming
    Replies: 8
    Last Post: 01-10-2007, 06:35 AM
  3. String Manipulation problems -_-
    By Astra in forum C Programming
    Replies: 5
    Last Post: 12-13-2006, 05:48 PM
  4. contest problems on my site
    By DavidP in forum Contests Board
    Replies: 4
    Last Post: 01-10-2004, 09:19 PM
  5. DJGPP problems
    By stormswift in forum C Programming
    Replies: 2
    Last Post: 02-26-2002, 04:35 PM