Thread: Keyboard Simulation

  1. #1
    Registered User
    Join Date
    Jun 2006
    Posts
    47

    Keyboard Simulation

    I was wondering what toolkit or C++ libraries or functions I would use to create a virtual keyboard, just like the default one in Windows. It does not need to be complicated, just very simple.

    Thanks!
    Windows XP Service Pack 2
    Borland C++ Compiler Version 5.5

  2. #2
    MFC killed my cat! manutd's Avatar
    Join Date
    Sep 2006
    Location
    Boston, Massachusetts
    Posts
    870
    1) Solution will be Windows specific, so move.
    2) Use a GUI toolkit (win32, wxWigdets, MFC, etc), and make all of the keys buttons. When one is clicked, you'll get some sort of message, which you may then handle.
    Silence is better than unmeaning words.
    - Pythagoras
    My blog

  3. #3
    Registered User
    Join Date
    Jun 2006
    Posts
    47
    Okay. I know wxWidgets, so that's good, but do you know what code syntax I would use to simulate a keypress? That's all I need, really.

    Thanks!
    Windows XP Service Pack 2
    Borland C++ Compiler Version 5.5

  4. #4
    (?<!re)tired Mario F.'s Avatar
    Join Date
    May 2006
    Location
    Ireland
    Posts
    8,446
    I/O libraries usually implement key mappings that you can alter with some judicious macro editing. For the console the ncurses library is one example. For those keys not defined, you can use getch() to completely reconfigure your kyboard if you so wish.

    As for windows... I don't know.
    Originally Posted by brewbuck:
    Reimplementing a large system in another language to get a 25% performance boost is nonsense. It would be cheaper to just get a computer which is 25% faster.

  5. #5
    (?<!re)tired Mario F.'s Avatar
    Join Date
    May 2006
    Location
    Ireland
    Posts
    8,446
    > Okay. I know wxWidgets, so that's good, but do you know what code syntax I would use to simulate a keypress? That's all I need, really.

    http://www.wxwidgets.org/manuals/2.6...xkeyevent.html
    Originally Posted by brewbuck:
    Reimplementing a large system in another language to get a 25% performance boost is nonsense. It would be cheaper to just get a computer which is 25% faster.

  6. #6
    Registered User
    Join Date
    Jun 2006
    Posts
    47
    I looked over wxKeyEvent, but it seems that can only be used for reading characters.

    I read about some I/O libraries. Would stdio.h be able to be used for a virtual keyboard?
    Windows XP Service Pack 2
    Borland C++ Compiler Version 5.5

  7. #7
    (?<!re)tired Mario F.'s Avatar
    Join Date
    May 2006
    Location
    Ireland
    Posts
    8,446
    Yes. It could, if I actually understand what you are trying to do.

    You could wrap functions like getc and putc to devise your own keyboard events.
    Originally Posted by brewbuck:
    Reimplementing a large system in another language to get a 25% performance boost is nonsense. It would be cheaper to just get a computer which is 25% faster.

  8. #8
    Registered User
    Join Date
    Jun 2006
    Posts
    47
    Yeah, I probably don't understand too much about what I'm trying to do.

    I've found a few Win32 functions (keybd_event(), SendInput()) for keyboard output, but that still doesn't solve my problem of being cross platform. I always like to have a way for my program's source code to be compiled on a different machine and work. It doesn't look like there is going to be a way to do this, though.
    Windows XP Service Pack 2
    Borland C++ Compiler Version 5.5

  9. #9
    Reverse Engineer maxorator's Avatar
    Join Date
    Aug 2005
    Location
    Estonia
    Posts
    2,318
    There is an easy way to do this. You use #ifdef-s and #ifndefs so it uses different code in different OS.
    "The Internet treats censorship as damage and routes around it." - John Gilmore

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, 04: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, 10:00 AM
  4. Keyboard hook
    By joecaveman in forum Windows Programming
    Replies: 2
    Last Post: 09-03-2005, 08:07 AM
  5. Game Design Topic #2 - Keyboard or Mouse?
    By TechWins in forum Game Programming
    Replies: 4
    Last Post: 10-08-2002, 03:34 PM