473,472 Members | 2,128 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

How to hook the keyboard to control unfocused or hidden form?

HaLo2FrEeEk
404 Contributor
I'm using a class I got ff o CodeProject called globalKeyboardHook:

http://www.codeproject.com/KB/cs/CSLLKeyboardHook.aspx

It hooks into the keyboard and allows my application to catch keyboard input even if the application is not focued or is hidden. I'm having a problem though.

I've got a few different hotkeys set up in my application, which uses a child form as the bounds to take a screenshot of a portion of the screen. You can hit F9 to take a screenshot and the program will ask you where to save it. F2 takes a screenshot and automtically saves it to the last save location. Finally, F3 copies the screenshot to your clipboard, but doesn't save it to a file. These all work as expected when the program is focused, and F9 and F2 work as expected when not focused, but F3 for some reason won't work unless the form has focus. I don't understand why F2 would work and not F3, they're essentially the same.

I tried using the hook class' KeyUp event handler instead of the KeyDown one and the same thing happened. I did put a breakpoint in at the event handler for the hook. It does exactly what it should, catches the F3, runs the copyToClipboard method, which gets the screenshot from the graphics object using CopyFromScreen(). Here is my method:

Expand|Select|Wrap|Line Numbers
  1. private void copyShotToClipboard()
  2. {
  3.     using (Bitmap wnd = takeScreenshot())
  4.     {
  5.         Clipboard.SetImage(wnd);
  6.         lblNotify.Text = "Copied to Clipboard";
  7.         SilentNotify();
  8.     }
  9. }
takeScreenshot() does the actual work of copying the screen pixels. SilentNotify() is a method that uses a background worker to fade a little notification that a silent task was performed (F2 and F3 both do this). When the window is focused then it works as expected, which leads me to believe that it has something to do with the clipboard permissions, but I can't find how to actually change the permissions...or even see them, for that matter.

How can I solve this? I have to dispose the bitmap to keep memory usage down, but when I dispose of it, even code that comes before it won't work anymore...which makes absolutely no sense. Take this slightly different example method:

Expand|Select|Wrap|Line Numbers
  1. Bitmap wnd = takeScreenshot();
  2. Clipboard.SetImage(wnd);
  3. lblNotify.Text = "Copied to Clipboard";
  4. SilentNotify();
  5. wnd.Dispose();
Even though the image is disposed of AFTER I set it to the clipboard...it still doesn't work, I get a System.ArgumentException. I don't get it.

I'm sorry this is so long, I just wanted to completely explain what was happening. Please help me out with this, I'm stuck on this project unless I can get this fixed.
Feb 4 '11 #1
0 1189

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: GoCMS | last post by:
Hi, guys: I am trying debug other people(who has left company)'s ASP code, and had difficulty understanding the use of a hidden asp page. The application has an index page, like MyIndex.asp...
8
by: Mike R | last post by:
Hi, I have a form frm1 . The form is generated by a "control" that is placed on the page - I have no access to the source to modify the controls. I can access other hidden controls within it...
5
by: MLH | last post by:
Private Sub UnhideDBwndowBtn_Click() SendKeys "~" DoCmd.DoMenuItem A_FORMBAR, 4, 4, 0, A_MENU_VER20 End Sub If I run the above code, database window 'unhides' and is displayed. However, on...
5
by: MLH | last post by:
You know, mouse movements - that sort of thing. I would just like an easy way for a hidden form NOT having the focus to know if the app is just sitting there running by itself, all alone with no...
2
by: Bob [BVP] | last post by:
I have a need to pass hidden form data on a Aspx form to a plain vanilla Asp page.. with it remaining hidden, and not using session/state cludges.. Thanks for any info. Bob
14
by: Paul | last post by:
I want to set the page title and/or a form hidden field programatically through ASP.Net. I do not want to use something like... <% sTitle ="My Title" %> <html><title><%=sTitle%></title>..... ...
12
by: Alan Silver | last post by:
Hello, I have a page that gets passed an ID in the query string. It then uses this ID to pull info out of a database and populate controls on the page. When the page is posted back, the query...
5
by: Thor W Hammer | last post by:
In ASP.NET 2.0, it seems to wrap a div around the hidden form fields such as __ViewState. How do you override this rendering?
3
by: Joe | last post by:
Hello All: I have two webforms (WebForm1.aspx and WebForm2.aspx) that inherit from BasePage.aspx. BasePage.aspx inherits System.Web.UI.Page and has one hidden field (hdnSessionId) that I want...
3
by: simora | last post by:
Hi: Need some working sample code to post hidden form data from a php page to a new popup window. 540 x 500 centered. The popup that I'm calling already is formatted and has a TITLE:web-2007.php...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.