Is there a way to simulate a keystoke through C++?
Is there a way to simulate a keystoke through C++?
Not in standard C++. Which platform are you using?
Dev-C++
I meant operating system, but that tells enough.
First functions that pop to my mind are SendInput and SendMessage. Check MSDN for info.
You should throw Dev-C++ away. Now. It hasn't been updated in years, last commit was made in 20.8.2005. Get something which is more up to date.
Depends if you use Linux, Window$ or Mac.
On Windows, try SendMessage/SendInput.
The best way to contact me is by email, which you can find on my website: http://wizzup.org
I also get email notifications of private messages, though.
Simba (on Twitter | Group on Villavu | Website | Stable/Unstable releases
Documentation | Source | Simba Bug Tracker on Github and Villavu )
My (Blog | Website)
is there a crosser platform way?
SCAR Tutorials: The Form Tutorial | Types, Arrays, and Classes
Programming Projects: NotePad | Tetris | Chess
The best way to contact me is by email, which you can find on my website: http://wizzup.org
I also get email notifications of private messages, though.
Simba (on Twitter | Group on Villavu | Website | Stable/Unstable releases
Documentation | Source | Simba Bug Tracker on Github and Villavu )
My (Blog | Website)
Here's some functions that supports OS X (this isn't C++, it's just C, but it should work just the same):
For other platforms, take a look at the "SendKeys" function under Keyboard.cpp in Scar++.Code:#if defined(__APPLE__) && defined(__MACH__) #define MACOSX 1 #else #error "I said this only supports OS X!" #endif #include <assert.h> // For assert() #include <ApplicationServices/ApplicationServices.h> // OSX-only header void toggleKey(UniChar c, const bool down) { CGEventRef keyEvent = CGEventCreateKeyboardEvent(NULL, 0, down); assert(keyEvent != NULL); CGEventSetFlags(keyEvent, 0); CGEventKeyboardSetUnicodeString(keyEvent, 1, &c); CGEventPost(kCGSessionEventTap, keyEvent); CFRelease(keyEvent); } inline void tapKey(UniChar c) { toggleKey(c, true); toggleKey(c, false); } inline void typeString(CFStringRef str) { unsigned i, len = CFStringGetLength(str); for (i = 0; i < len; ++i) { tapKey(CFStringGetCharacterAtIndex(str, i)); } }
There are currently 1 users browsing this thread. (0 members and 1 guests)