Announcement

Collapse
No announcement yet.

Programmers, could somebody do this?

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Programmers, could somebody do this?

    Hey guys, I know a lot of the people here are programmers (seems a lot of VB people).

    I was wondering if anybody would be willing to write this simple app for a project of mine:

    Starts and goes to tray
    Sits there and saves to a file the ASCII code of the last key pressed
    Exits when run again
    Deletes file on exit

    Please note, this is not a keylogger, I only want to know the current or last key pressed.

    So, tell me if this can be done and if so, how much $$$ (or maybe I could give you some kind of gift).

    Please be reasonable.

    TIA.

  • #2
    Well the only problem I see with this (using c/c++, I have never touched VB) is that files are buffered into memory until they are closed then they are flushed. Im assuming your going to write another program that will open this file and read in the last key pressed and do something based on that. The problem is that logging program will be writing this out to the buffer, and the file itself will not actually be on disk untill the file is closed and the buffer flushed. So in other words, the program would have to open the file (overwriting any other stuff in the file), write one ascii code, then close the file, repeat this for EACH key pressed.

    Now to get around that, I could write a program that will send your program a message with the ascii code attached to it (via the winAPI PostMessage( ) function). All you would have to do really is handle an event for (WM_USER + 1) in VB which will have attached to it via the lparam parameter the ascii code. All I would need is the name of your program as it appears in the title bar or its class name. Then you can just do a giant switch statement (or whatever VB likes to call switch statements) :P
    '03 BMW M3 6 spd.
    Black/Imola Red
    19's

    Shuttle XPC w/ AMD 1800+
    Opus 150w
    Lilliput 7"
    Wireless internet through my P900 and bluetooth

    Comment


    • #3
      Thanks for the reply man. Actually, you're right, I will use a nother program to read this file and do something when the user presses ESC. Your concern about the contant file writing is the system load? Because the way I pictured it, it won't write so much.

      So, here's my idea of the pseudo-code, does this work?

      Start loop
      Check key pressed
      If key = nothing, then begin loop again
      open file
      write key to file
      close file
      begin loop again

      You see, my end it to close a window showing a movie when the person presses ESC. So, most of the time there won't be any keypresses, thus no file writing. What do you think.

      Oh, as far as the sending a message to the App, I don't know how that would work. The app that will check for the ESC and send Alt+F4 to the movie viewer is AutoIt.

      Thanks again.

      Comment


      • #4
        Well what exactly are you trying to do? Are you trying to send a message to a third party app to shutdown if you hit esc in YOUR program? I was a little confused with what you said... Maybe I can come up with a better way? Also, there may not be much file writing, but you have to remember that the program you write will need to continuously open the file, check whats in it, and close it, regardless of whether or not a key was actually pressed.

        Additionally, there would be sync problems because the logger could open the file right as your program is opening the file and obviously that wont work since the logger would be opening the file in write mode. I just think there is a much easier way to do this without having to go through a file.
        '03 BMW M3 6 spd.
        Black/Imola Red
        19's

        Shuttle XPC w/ AMD 1800+
        Opus 150w
        Lilliput 7"
        Wireless internet through my P900 and bluetooth

        Comment


        • #5
          Ok, let me be as specific as I can.

          I am using a scripting program called AutoIt (http://www.hiddensoft.com/AutoIt). This scripting language allows me to do a bunch of things, wait for a window, close it, maximize it, send keys to it, etc. Unfortunately there is no way for it to detect keypresses and act accordingly. It does have a command to read a line form a file. My idea was then to have some sort of keylogger write only the last key pressed to a file, have AutoIt read this file (constantly, you're right), and close a Window when the ASCII = 27 (ESC).

          These two programs will run on an computer/arcade machine that has no keyboard plugged into it, only a few buttons. One of those buttons is ESC. I want to watch flash movies on this arcade machine, so I wrote a script that launches the Flash Movie Player, and it sends its keys to go fullscreen. The problem is that when I push ESC, the window just restores to the original size, but doesn't close. Hence the need for the above method. I wouldn't like to have an app that only works for the Flash Player though, since I want to do the same for other programs.

          Hopefully that explains it better.

          Comment


          • #6
            Gotcha, Ill take a look at that and see if I can come up with any ideas... Looks like an intresting program!
            '03 BMW M3 6 spd.
            Black/Imola Red
            19's

            Shuttle XPC w/ AMD 1800+
            Opus 150w
            Lilliput 7"
            Wireless internet through my P900 and bluetooth

            Comment


            • #7
              i think that it would be easier to create a porgram that closes flash when you press esc or some other key maybe the only problem is that flash takes the esc key
              ---

              Status: I still need to get some money to buy the inverter.

              Comment


              • #8
                InFix: Thanks again man. Yeah, that AutoIt comes in handy. I use it all the time, I must have written over 20 full-fledged scripts for it now (installations, backups, you name it).

                jure1873: You're right, but I was thinking it would be cool to use it for other things, besides Flash. I obviously don't know a lot of 'real' programming, otherwise that is definetively the route I would follow.

                Comment


                • #9
                  Check out Girder (girder.nl), you can automate windows like autoit and it has a keyboard input devicec built in..

                  jason

                  Comment


                  • #10
                    infrared: Thnx for the offer. I actually already use girder for some other things, but this is a different animal.

                    InFix: Look what I came up with. I found some examples of keyloggers from http://planetsourcecode.com and I modified the hell out of one of them and attached is the result.

                    This program will run on a small window and save most (not all) keystrokes to a keylog.txt file in its working directory. This proggie will take care of my needs for now, but I really need a more 'professional' solution (read: something that reads any possible key entered, including Function keys, Ctrl, etc). I've expanded what I would like my dream program to do because I have some other ideas now.

                    Also, I found out that AutoIt can read from enviroment variables, so maybe a program that sets ERRORLEVEL to the last key or keycombination?

                    Anyway, thanks for the help, and let me know if my new idea is doable.

                    Comment


                    • #11
                      Ah sorry for not replying man, life's been kind of hectic this week :/ (employer filed chapter 11, and was kind enough to let me know on Monday that Friday was my last day there, lol). Things should slow down a bit this weekend, and Ill take a look at that stuff and let you know!
                      '03 BMW M3 6 spd.
                      Black/Imola Red
                      19's

                      Shuttle XPC w/ AMD 1800+
                      Opus 150w
                      Lilliput 7"
                      Wireless internet through my P900 and bluetooth

                      Comment


                      • #12
                        Infix: Don't worry dude, no hurry. I'm really sorry to hear you lost your job. I'm about to lose mine too, (the school will only employ you if you are a student there, and I'm about to transfer), but at least I'm not the breadwinner of my house, which I'm sure you are.

                        Just take your time, I appreciate the help regardless.

                        Good luck.

                        Comment


                        • #13
                          Is there a way to make a button that would send alt+F4 command to windows, instead of trying to do all that? maybe that would be easier to program? like have it run on a loop, until the last key pressed is "ESC" or whatever, and send an API call to close the active window? I don't know much about windows API, i'm still learning console C++..
                          Just an idea
                          -Matt

                          Comment


                          • #14
                            Hey man, give me the *exact* text that is in the apps title bar (the one you are trying to close), and Ill write up a quick little test app to see if something works. Its basically going to be a simple little dialog proggy with one button. When you press the button, it will close the other window. If that works, the I can write a quick keylogger for you that will send the same message when esc is hit (in *any* program). So basically it will do the same thing, except you dont have to hit a button. If you could take a screen shot of the app running and post it, that would be the best way to do it :-P
                            '03 BMW M3 6 spd.
                            Black/Imola Red
                            19's

                            Shuttle XPC w/ AMD 1800+
                            Opus 150w
                            Lilliput 7"
                            Wireless internet through my P900 and bluetooth

                            Comment


                            • #15
                              Originally posted by AlchemisT
                              Is there a way to make a button that would send alt+F4 command to windows, instead of trying to do all that? maybe that would be easier to program? like have it run on a loop, until the last key pressed is "ESC" or whatever, and send an API call to close the active window? I don't know much about windows API, i'm still learning console C++..
                              Just an idea
                              -Matt
                              MFC:
                              Code:
                              CWnd *targetApp = FindWindow(NULL, "Your app's title as it appears in its title bar");
                              targetApp->SendMessage(WM_EXIT);

                              pure winAPI would look like:
                              Code:
                              HWND targetApp = FindWindow(NULL, "Your app's title as it appears in its title bar");
                              SendMessage(targetApp , WM_EXIT, 0, 0);
                              Thats just to close the app from an extrenal app. To monitor for "esc", you need to set a system wide hook, which is basically a "checkpoint" for windows message. This hook must be installed into windows using a .dll, so I dont know if you can write dll's in VB, but you can easily write one in VC++. You then write another program that the dll will send messages to (namely, which key was pressed). When this program sees that esc was pressed, it will send the WM_EXIT message to the app that needs to be closed.

                              :-)
                              '03 BMW M3 6 spd.
                              Black/Imola Red
                              19's

                              Shuttle XPC w/ AMD 1800+
                              Opus 150w
                              Lilliput 7"
                              Wireless internet through my P900 and bluetooth

                              Comment

                              Working...
                              X