Keyboard Simulation

This is a discussion on Keyboard Simulation within the C++ Programming forums, part of the General Programming Boards category; I was wondering what toolkit or C++ libraries or functions I would use to create a virtual keyboard, just like ...

  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
    Portugal
    Posts
    7,574
    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.
    The programmer’s wife tells him: “Run to the store and pick up a loaf of bread. If they have eggs, get a dozen.”
    The programmer comes home with 12 loaves of bread.


    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
    Portugal
    Posts
    7,574
    > 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
    The programmer’s wife tells him: “Run to the store and pick up a loaf of bread. If they have eggs, get a dozen.”
    The programmer comes home with 12 loaves of bread.


    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
    Portugal
    Posts
    7,574
    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.
    The programmer’s wife tells him: “Run to the store and pick up a loaf of bread. If they have eggs, get a dozen.”
    The programmer comes home with 12 loaves of bread.


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

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