Solved

simulate a key press

Posted on 2003-11-11
8
2,241 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
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
java ^ examples 8 62
copyEndy  challenge 15 83
object oriented javascript web form 8 100
Interview question Javascript, database 12 25
Having just graduated from college and entered the workforce, I don’t find myself always using the tools and programs I grew accustomed to over the past four years. However, there is one program I continually find myself reverting back to…R.   So …
This article is meant to give a basic understanding of how to use R Sweave as a way to merge LaTeX and R code seamlessly into one presentable document.
This video teaches viewers about errors in exception handling.
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.

914 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now