Sending Print Screen keypress

B

BobRoyAce

My first question is "How can I have my application simulate the user
pressing a key?"

Next, how can I have it simulate pressing the Print Screen key? I saw
something about a SendKeys function, though not sure if that's what I
should be using, and, if so, how I reference it. However, if that is
the method, it would appear that one is not allowed to pass the Print
Screen to that method. In other words, it won't do that one keypress.
If that method, or some other better method, won't allow sending the
Print Screen keypress, is there a way that I can map a function key
combination to the Print Screen key, and then send the mapped key
sequence instead?
 
O

Onur Güzel

My first question is "How can I have my application simulate the user
pressing a key?"

Next, how can I have it simulate pressing the Print Screen key? I saw
something about a SendKeys function, though not sure if that's what I
should be using, and, if so, how I reference it. However, if that is
the method, it would appear that one is not allowed to pass the Print
Screen to that method. In other words, it won't do that one keypress.
If that method, or some other better method, won't allow sending the
Print Screen keypress, is there a way that I can map a function key
combination to the Print Screen key, and then send the mapped key
sequence instead?

SendKeys function allows you to send Print Screen key using:
' That function is also included in System.Windows.Forms
SendKeys.Send("{PRTSC}")

However, based on my test, it captures only form area instead of
entire screen unlike traditional print screen behaviour on keyboard.

Hope this helps,

Onur Güzel

Onur Güzel
 
H

Herfried K. Wagner [MVP]

BobRoyAce said:
My first question is "How can I have my application simulate the user
pressing a key?"
'SendKeys.Send'.

Next, how can I have it simulate pressing the Print Screen key? I saw
something about a SendKeys function, though not sure if that's what I
should be using, and, if so, how I reference it.

Take a look at the documentation on the above method.

In addition, you may want to take a look at the 'Graphics.CopyFromScreen'
method, which might be suitable depending on the exact scenario too.
 
B

BobRoyAce

My first question is "How can I have my application simulate the user
'SendKeys.Send'.

That works for sending characters to a control on the form, for
example, but it doesn't seem to work for sending a keypress to trigger
my screen capture software. For example, I have set my screen capture
program to save an image of the active window when I press the F7 key.
When I'm not running my application, and I press F7 key, it works like
a charm. However, if I run the following code...

SendKeys.Send("{F7}")

from within my application, nothing happens. The KeyPreview property
of the form is set to False, in case that is relevant. Is my
application somehow "consuming" the send of that key, thereby keeping
my screen capture software from ever noticing it? If so, how would I
get around this?
In addition, you may want to take a look at the 'Graphics.CopyFromScreen'
method, which might be suitable depending on the exact scenario too.

I'll have to check that out. Is there a function like that that I can
use to grab the image of a form (i.e. save image of form as a graphic
file)?
 
H

Herfried K. Wagner [MVP]

BobRoyAce said:
That works for sending characters to a control on the form, for
example, but it doesn't seem to work for sending a keypress to trigger
my screen capture software. For example, I have set my screen capture
program to save an image of the active window when I press the F7 key.
When I'm not running my application, and I press F7 key, it works like
a charm. However, if I run the following code...

SendKeys.Send("{F7}")

from within my application, nothing happens. The KeyPreview property
of the form is set to False, in case that is relevant.

If your form is the form which currently has the input focus, the F7 key
will be sent to your application. You'd have to bring the other application
into the foreground ('AppActivate'/'Process' + p/invoke
'SetForegroundWindow').
I'll have to check that out. Is there a function like that that I can
use to grab the image of a form (i.e. save image of form as a graphic
file)?

Yes, you can do that. Take a look at the classes 'Bitmap' and 'Graphics',
and especially at the 'Graphics.FromImage' method.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top