keyboard fonctions

This is a discussion on keyboard fonctions within the Windows Programming forums, part of the Platform Specific Boards category; Hey guys, Im using this code to write "hi" to notepad: Code: #define _WIN32_WINNT 0x0500 #include "windows.h" void SendKey(BYTE vKey) ...

  1. #1
    Registered User
    Join Date
    Mar 2007
    Posts
    38

    keyboard fonctions

    Hey guys,

    Im using this code to write "hi" to notepad:
    Code:
    #define _WIN32_WINNT 0x0500 
    #include "windows.h"
    
    void SendKey(BYTE vKey)
    {
    INPUT Input;
    ZeroMemory(&Input, sizeof(Input)); 
    Input.type = INPUT_KEYBOARD; 
    Input.ki.dwFlags = KEYEVENTF_EXTENDEDKEY;
    Input.ki.wVk = vKey; 
    SendInput(1, &Input, sizeof(INPUT));
    }
    
    int main()
    {
    HWND Notepad = FindWindow("Notepad", 0);
    if(!Notepad) return 0;
    
    SetForegroundWindow(Notepad);
    Sleep(500);
    
    SendKey((UCHAR)VkKeyScan('h'));
    SendKey((UCHAR)VkKeyScan('i'));
    return 0;
    }
    But if the notepad is minimized it won't work. Is there a way to write "Hi" to it WHILE IT IS MINIMIZED?

  2. #2
    For Narnia! Sentral's Avatar
    Join Date
    May 2005
    Location
    Narnia
    Posts
    719
    Should be in Windows Programming...
    Videogame Memories!
    A site dedicated to keeping videogame memories alive!

    http://www.videogamememories.com/
    Share your experiences with us now!

    "We will game forever!"

  3. #3
    Captain - Lover of the C
    Join Date
    May 2005
    Posts
    341
    keybd_event
    Don't quote me on that... ...seriously

  4. #4
    Registered User Queatrix's Avatar
    Join Date
    Apr 2005
    Posts
    1,342
    I think keybd_event() is obsolete.

  5. #5
    Captain - Lover of the C
    Join Date
    May 2005
    Posts
    341
    It works.
    Don't quote me on that... ...seriously

  6. #6
    Registered User Queatrix's Avatar
    Join Date
    Apr 2005
    Posts
    1,342
    So does void main.

    EDIT:

    But to answer NoFearXD's question...

    The answer is no, as you cannot type anything in Notepad while minimized, SendInput() and keybd_event() just "virtually press the key", they can't do anything you can't.

    You could however, use FindWindow() to get Notepad, then find the child edit using FindWindowEx(), then using SetWindowText(). That would work even if it's minimized.
    Last edited by Queatrix; 04-12-2007 at 10:26 PM.

  7. #7
    Registered User
    Join Date
    Mar 2007
    Posts
    38
    All right! thanks

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Detecting keyboard and mouse in linux
    By sameer.nalwade in forum C Programming
    Replies: 3
    Last Post: 11-22-2008, 03:24 AM
  2. Keyboard port using other that a keyboard
    By antoinelac in forum C++ Programming
    Replies: 4
    Last Post: 06-12-2008, 02:46 PM
  3. Virtual keys
    By Arkanos in forum Windows Programming
    Replies: 4
    Last Post: 12-12-2005, 09:00 AM
  4. What type of keyboard is this?
    By 7smurfs in forum Tech Board
    Replies: 5
    Last Post: 06-22-2005, 05:09 PM
  5. Game Design Topic #2 - Keyboard or Mouse?
    By TechWins in forum Game Programming
    Replies: 4
    Last Post: 10-08-2002, 03:34 PM

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