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
Solved

simulate a key press

Posted on 2003-11-11
8
2,252 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
Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

 
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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
countHi2 challenge 7 59
Need To Find FireFox Binary Path For Python Selenium On Windows 7 15 709
groovy example issue 10 103
convert Systemjs to Webpack 3 31
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…
When we want to run, execute or repeat a statement multiple times, a loop is necessary. This article covers the two types of loops in Python: the while loop and the for loop.
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.

856 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