Solved

simulate a key press

Posted on 2003-11-11
8
2,238 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

 
LVL 3

Assisted Solution

by:RJSoft
RJSoft earned 40 total points
Comment Utility
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
Comment Utility
Have a look at the javadocs for java.awt.Robot.
0
 
LVL 1

Expert Comment

by:vbs03
Comment Utility
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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Navigation is an important part of web design from a usability perspective. But it is often a pain when it comes to a developer’s perspective. By navigation, it often means menuing. This is less theory and more practical of how to get a specific gro…
Windows Script Host (WSH) has been part of Windows since Windows NT4. Windows Script Host provides architecture for building dynamic scripts that consist of a core object model, scripting hosts, and scripting engines. The key components of Window…
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.
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

762 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

7 Experts available now in Live!

Get 1:1 Help Now