Solved

simulate a key press

Posted on 2003-11-11
8
2,253 Views
Last Modified: 2010-05-18
Hi!

Maybe my question is very simple but I have no idea how to do it....
here´s my problem...

I have to take a screenshot of my computer every day at the same time and upload it to a server...
I was thinking to use a scheduled task in Windows to do this...after a long search for the right capturing program, Screenshot Utility 1.0 was the best I could find.
In this program you can configure your capture key and then de screenshot wil be saved at a pre-defined place.
Now for my question, I need to make a program wich simulates a press on the keyboard(for example C)...
I have no idea how to do that...The languages i know are powerbuilder, java en PHP...
but maybe I´ll have to use VB.

How can I do it the best and easiest way?!?!

thanks in advance,

willem
0
Comment
Question by:wbph
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
8 Comments
 
LVL 2

Accepted Solution

by:
mattaustin earned 40 total points
ID: 9726757
http://www.erginsoft.com/products/esc/ offers a commandline program to get a screen capture you could emulate this with:

system(C:\esc.exe desktop.bmp);

otherwise you may want to look into Gimp or GD to see if it offers anything for screen capture.
0
 
LVL 5

Assisted Solution

by:fantasy1001
fantasy1001 earned 40 total points
ID: 9726957
You can do the screen shot pretty easy with VB:

Step:
Include the keybd_event API in your project
then add this code

Private Declare Sub keybd_event Lib "user32" (ByVal bVk As Byte, ByVal bScan As Byte, ByVal dwFlags As Long, ByVal dwExtraInfo As Long)

Private Sub Command1_Click()
    keybd_event vbKeySnapshot, 0, 0, 0
    SavePicture Clipboard.GetData, "c:\my.jpg"
End Sub
0
 
LVL 45

Assisted Solution

by:sunnycoder
sunnycoder earned 40 total points
ID: 9728438
just try if shell redirection works for you

command_prompt] path/to/executable < inputfile

in the inputfile just store the input you wish to provide .... in this case character c
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 3

Assisted Solution

by:RJSoft
RJSoft earned 40 total points
ID: 9728461
In C++ VC it is harder to do.

After creating your application (via VC wizard (the easy way)) maybe a dialog based application. you might do this.

First setup a timer for the main class window. Basically the timer acts like a thread and runs in background. You can also hide your application in the background with ShowWindow api (SW_HIDE).

The timer thread can then be used to call up some function that you design to test how much elapsed time has passed. Something like GetTime which uses a structure that counts the number of seconds since 1970 or something like that. What you could do then is store to a file a starting time ( a first number of seconds since 1970) and then subtract that from the current number of seconds. That is how you could calculate the number of hours and minutes and seconds that have passed since the last time you took a screen shot. When that condition is met then use api SendMessage. Then you could send WM_KEYDOWN and set the WParam and lParam members to what the Print Screen Key is. Then also re-write the value of your first seconds to the current seconds.

If you can not get the SendMessage to work then you can also do it another way which is more difficult yet. You can save your screen as a bitmap. If you want that code I can send it to you. Then all you would have to do is call the function and the screen would be saved in a bitmap file.

RJSoft
0
 
LVL 15

Assisted Solution

by:jimmack
jimmack earned 40 total points
ID: 9733091
Have a look at the javadocs for java.awt.Robot.
0
 
LVL 1

Expert Comment

by:vbs03
ID: 9753434
Hi,
Very easy. To type a charcter say "C" through VB app, just use function:

Sendkeys("C")

This will type the character "C" on the current visible application.
Regards,
vbs03
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
bigDiff challenge 17 134
Choosing the right language for new project 8 66
base64 decode encode 12 164
Non-recursive backtracking, using a stack 1 244
There is an easy way, in .NET, to centralize the treatment of all unexpected errors. First of all, instead of launching the application directly in a Form, you need first to write a Sub called Main, in a module. Then, set the Startup Object to th…
Whether you’re a college noob or a soon-to-be pro, these tips are sure to help you in your journey to becoming a programming ninja and stand out from the crowd.
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.

749 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question