|
-
Feb 15th, 2009, 01:55 PM
#1
Thread Starter
Addicted Member
Mouse Hook? Or am I going about this wrong.
Hi, I think I would need a mouse hook to accomplish my task. But anyway, basically I want to get a mouse click (down) get the coordinates, then while its dragging if possible draw a box then when released get the coordinates of the second point. Thus then I can use these rectangle coordinates.
Does this have to be done in a hook? I do want it outside of my application, hence automatically thought "hook". To be honest, I think I really understand hooks fine, but then someone's example on the internet confuses me.
Oh the overall effect I want is to be able to take screenshots from a specific portion of the screen. Lame right? I just heard about apples utility of this and thought it was cool and wanted to make my own.
Appreciate input,
-Hiroshi
-
Feb 15th, 2009, 02:02 PM
#2
Re: Mouse Hook? Or am I going about this wrong.
-
Feb 15th, 2009, 02:04 PM
#3
Thread Starter
Addicted Member
Re: Mouse Hook? Or am I going about this wrong.
Alright, Thanks.. I'll check that out. Looks well documented.. Thanks =]
So global hooks are the way to go?
The only way? I don't know, I like knowing all the routes I can go to get somewhere in programming. Its my favorite part in programming.
-
Feb 15th, 2009, 02:07 PM
#4
Re: Mouse Hook? Or am I going about this wrong.
Hey,
If you are wanting to make a global screen shot utility, then yes, I think global hooks would be the best course of action. I could be wrong though, that is just my opinion.
Gary
-
Feb 16th, 2009, 01:10 PM
#5
Thread Starter
Addicted Member
Re: Mouse Hook? Or am I going about this wrong.
Okay, in the code you suggested. Well okay first of all, for some reason it won't let me see the Form in design view. I'm using 2005, maybe thats the problem--But it runs fine (thats weird).
I don't quite understand how this works. Let me try to explain what I think I get.
Each of these hooks are objects.
What links the objects to the functions that handle the keypress?
AND this code:
Code:
<DebuggerHidden()> _
Protected Overridable Sub OnKeyDown(ByVal e As WindowsHookLib.KeyBoardEventArgs)
RaiseEvent KeyDown(Me, e)
End Sub
DebuggerHidden? so you can't debug it? whats the purpose of that.
Also, when it raises "KeyDown(Me, e)" I don't understand how that knows what event to raise.
Could someone just maybe summarize how the flow works (just a psudocode explaination)
-
Feb 17th, 2009, 02:17 AM
#6
Re: Mouse Hook? Or am I going about this wrong.
Hello there,
Ok, so did you download the source code for the library, or did you download the demo project?
In the demo project, run the application, and then click on "Install Mouse Hook", for there on you can track the co-ordinates of the mouse, as well as get information about when the left mouse button is clicked, right mouse button clicked, as wheel as when the scroll wheel is used.
The same approach can be used for keyboard hook, simply click the "Install Keyboard Hook" button"
The DebuggerHiddenAttribute is nothing to worry about, it simply means that when you are debugging the code, i.e. setting break points and stepping through, that it will not stop within this method. The reason you would do this would be, for instance, becuase you know that part of the code definitely works, or that you gain nothing by stepping into it.
I also get the error in the Design View. It is maybe worth PM'ing the original author, or respond to his thread to see if he can suggest anything.
To be honest, I have not looked at the innards of the code that I pointed you to, so I would need to spend some time looking into it to explain it. Having said that though, I have played with the library in the past, and I was able to knock up a very simple example, I don't remember having any real problems with using it.
Gary
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|