views:

598

answers:

3

I'm working on a document application and part of this application I've to add support to read the keyboard pressed events and replace the pre-defined characters set if that keyboard entry is match with the pre-defind short form/word.The actual application has implemented in C++.

Please provide me your thoughts on how to implement this. Is there any sample C++ program for reference? algorithm/concepts?

A: 

Standard C++ doesn't support keypress events, so you'll have to look at either an OS function, or a framework function. Portable C++ frameworks like wxWidgets or Qt support keypress events on Windows, Mac and Linux.

MSalters
The actual application is implemented with C++ and Wxwidgets. is there will be any documnetation for this?
Thi
+1  A: 

Learn how to catch the keydown events using wxWidgets api, maybe here: http://docs.wxwidgets.org/stable/wx_eventhandlingoverview.html#eventhandlingoverview pay attention to key events. Implement a switch in C++ to see what key combination was pressed, and set the text to the edit accordingly. What I'm thinking about here is to convert a CTRL-SHIFT-A keypress to a text like Ctrl-Shift-a in a edit box.

If you are thinking of converting a combination of characters to other character, for example kanji or hiragana, the algorithm could be longer and more data structures required.

rec
A: 

If you are under Windows you can use the GetAsyncKeystate API call and watch for changes, or use the low-level keyboard hooks (slightly more complicated) (CreateHookEx + related functions).

Under DOS (or possibly Linux) you can use _kbhit in conio.h in console mode, i usually stick this in a loop (while(!_kbhit());) for a "press any key to continue", but using _getch can retrieve the key which was pressed

jheriko