There is an API which allows you to get the coordinates of the cursor position, there is another API which will allow you to set the cursoe pos to some coordinates.....i cant remember them off the top of my head but a quick search would probably find them.
So you could make a timer which uses the getcursorpos api to store the cursor positions in maybe a array? and then you could save it to a text file if you wanted.
Then of course use another timer and put the setcursor pos api to the previous coordinates, and this would play the recorded coordinates back
You should use a journal hook for this purpose, the system will then call a CallBack procedure in your app for each input message the system removes from the system queue.
To do this you'll call the SetWindowsHookEx API function using the WH_JOURNALRECORD hook. You'll then have to create the callback function in a regular bas module. I currently don't have any example code for this, but I'm pretty sure some exist in this forum. If you can't find out how to do this let me know and I'll create a sample application for you.
You should use a journal hook for this purpose, the system will then call a CallBack procedure in your app for each input message the system removes from the system queue.
To do this you'll call the SetWindowsHookEx API function using the WH_JOURNALRECORD hook. You'll then have to create the callback function in a regular bas module. I currently don't have any example code for this, but I'm pretty sure some exist in this forum. If you can't find out how to do this let me know and I'll create a sample application for you.
Anyway if you have been using vb for a month isnt creating a game client a little ambitions? Maybe you should go with the walk before you run saying.
eh, im always over ambitious, and neway...im (quite) clever for my age. and, if i learn more advanced stuff now, ill get a head start when im making even more advanced apps and start learning vb in school (if we ever do).
on top of that, im wanting to be a computer programmer when iv left uni (if i get qualifications and stuffs to get in), so it could hep in that sector aswell.
and its only a simple client for an online game, with an auto-talker and if i get my head round the code....a click recorder.
and with your saying; i could run before i could walk....
Last edited by haywood222; Feb 17th, 2006 at 05:21 PM.
Reason: forgot a part of it...lol
@Joacim - as he said hes new so unless example code is provided, telling him to use such and such api or hook this and that, means nothing!
So he did. In his reply to you that is but I didn't see that when I started typing my reply .
The cursor pos API functions are GetCursorPos and SetCursorPos. But using those in a Timer, as suggested, will only let you record the mouse position, not when a mouse button is clicked. Here's how you would declare those functions.
VB Code:
Private Declare Function GetCursorPos Lib "user32.dll" ( _
ByRef lpPoint As POINTAPI _
) As Long
Private Declare Function SetCursorPos Lib "user32.dll" ( _
ByVal x As Long, _
ByVal y As Long _
) As Long
Private Type POINTAPI
x As Long
y As Long
End Type
To get the coordinates of the mouse you would then use code simular to this:
VB Code:
Dim p As POINTAPI
Call GetCursorPos(p)
MsgBox "The current position of the mouse is at " & p.x & ", " & p.y
However the coordinates here will always be in screen coordinates and not in pixels meaning that the lower right position is always the same regardless of the screen resolution.
Using a journal hook is a bit advanced but you will get information about any input message windows handles which includes when the mouse is moved or one of the mouse buttons is pressed or released...
You can use the mouse_event api to simulate a click event after you set the mouseposition with the SetCursorPos function.
VB Code:
Private Declare Sub mouse_event Lib "user32" (ByVal dwFlags As Long, ByVal dx As Long, ByVal dy As Long, ByVal cButtons As Long, ByVal dwExtraInfo As Long)
Const MOUSEEVENTF_LEFTDOWN = &H2
Const MOUSEEVENTF_LEFTUP = &H4
Const MOUSEEVENTF_MIDDLEDOWN = &H20
Const MOUSEEVENTF_MIDDLEUP = &H40
Const MOUSEEVENTF_MOVE = &H1
Const MOUSEEVENTF_ABSOLUTE = &H8000
Const MOUSEEVENTF_RIGHTDOWN = &H8
Const MOUSEEVENTF_RIGHTUP = &H10
'Simulate a mouseclick on the cursor's position
mouse_event MOUSEEVENTF_LEFTDOWN Or MOUSEEVENTF_LEFTUP, 0&, 0&, 0&, 0&
To deny our own impulses is to deny the very thing that makes us human
I blame my headache, I thought it said to record the cursor positions and play back.
@haywood its good to see someone with so much interest in programming especially at that age - you remind me of me! - okay that makes me sound old....for the record im only 19
Have you looked into learning the newer visual basic .NET? If I was in your position if i would quit vb6 and begin learning .NET since you have only spent a month on it, its not a waste of time. By the time you leave university, vb6 classic will be like the programming language 'Basic' is now - almost totally obsolete and not used. Most big software development companies have already dropped vb6 and moved to .NET. Plus .NET has many advantages and is more powerful than vb6 classic. So if you learned .net it would be extremely beneficial to your career prospects
Maybe you'll find the attach class helpful. I wrote some time ago and it uses the GetCursorPos and the above mentioned mouse_event functions. With it you can get the cursor position and move the mouse or simulate click, dblclick or drag events very easily. It only has two properties, X and Y which returns the current mouse position, in pixels so the class translates the screen coordinates into pixels for you. You can also set these properties to new values to move the mouse, or you can call the MoveTo method to set both values in one go. The other methods the class has are Click, DblClick, StartDrag, and EndDrag. So if the mouse is currently positioned in the title bar of a window you can call the StartDrag method, then call MoveTo to move the mouse and finally call the EndDrag and you have moved the window the mouse was over.
Here's a quick example of how you use the class:
VB Code:
Dim mice As CMouse
Set mice = New CMouse
MsgBox "The current position of the mouse is " & mice.X & "," & mice.Y
'Move the mouse
mice.MoveTo 10, 25
'The above could also been done by changing the X and Y properties but
'in that case would have required these two calls:
' mice.X = 10
' mice.Y = 25
'Now let us click at the current position
mice.Click
EDIT: Sorry forgot the attachment
Last edited by Joacim Andersson; Feb 17th, 2006 at 05:58 PM.
nice class, I cant really see what it would be useful for other than this project or trojan horse programmers, if hes looking to learn maybe it would be better to do it the simplest way first like the way guyvdn mentioned and the way Joacim mentioned for getting the cursor pos and setting it, so you could shave off a big chunk of code and put that into a bas module, or even just on the form. Class modules are a subject of there own, really even though hes intelligent for his age it would be better for learning by doing it the simplest way, then progressing.
But of course if he just wants a quick solution to his problem then that class is perfect! Just put the mice.MoveTo and mice.x etc into a timer
nice class, I cant really see what it would be useful for other than this project or trojan horse programmers.
I use that class in many of my projects and I have yet not done any trojans . If you want to see a project in which I use it I'll suggest you'll have a look at my Window Finder tool in the CodeBank.
Class modules are a subject of there own, really even though hes intelligent for his age it would be better for learning by doing it the simplest way, then progressing.
I don't agree with this at all. Stating that classes are an advanced feature and something that newbies should stay away from is IMHO wrong. If you just started learning programming you should start learning how to write and use classes so you don't have to relearn how to program with them after you're stucked in the old school of procedural programming. Typing code in a class module is no different from typing it in a regular BAS module and we use objects and controls all the time anyway. Besides, it was you that suggested that he should hop on the .Net train in which he can't do anything really without encapsulating his code into classes.
I don't agree with this at all. Stating that classes are an advanced feature and something that newbies should stay away from is IMHO wrong. If you just started learning programming you should start learning how to write and use classes so you don't have to relearn how to program with them after you're stucked in the old school of procedural programming. Typing code in a class module is no different from typing it in a regular BAS module and we use objects and controls all the time anyway. Besides, it was you that suggested that he should hop on the .Net train in which he can't do anything really without encapsulating his code into classes.
using classes is a completely different type of programming to vb6 classic without classes. Classes are technically OOP object oriented programming, so its logical to know bas modules first...which of course are not OOP. I dont know any newbies who could explain what property get and let are used for and why, infact I have just asked my younger brother who is fairly new to vb6 and he replies 'why make it more complicated than it needs to be' which is exactly what i'd expect from a new vb6 programmer - and i couldnt agree more with him
@.net comment, he would be better off going straight to .net and beginning classes there instead of learning them in vb6 then making the change
Well, I don't agree at all. OOP is of course different from procedural programming but I don't agree that you must first learn procedural programming before you go into using object oriented programming. It's actually a bad idea to do so since that is when it gets hard because you'll need to learn to think in another way. Property Get is not harder to learn than to learn how to write a function and Property Let is not harder then learning how to write a Sub. You use properties as a newbie so why not learn how to write them. If you don't use classes you are essentially writing VB3 code. But I see from your test result from that ExpertRating exam that you haven't done so .
And where is your test result? I could list many qualifications which I have completed in my tag but I have learned from experience that posting them without proof makes you come across 'stuck up' and too 'snotty'. This is nothing more than wasting server space, and a waste of my and your time, I come here to help and answer questions not begin arguments or start personal matters which is exactly what you did in your last post
Sorry, I didn't mean to offend you in any way. What I meant is that from your test results I can see that when you learned VB you didn't learn how to use classes to start with. Well, neither did I but I started using VB as of version 1 and classes didn't exist back then . Again I apologize if I offended you, that was not my intention. I have not taken any of those ExpertRating exams and the results of the MCP exams I have taken is not available on the Net. Neither is the result of the Sun certification exam.
Apology accepted - well now this thread has turned into a chat system for you and I so maybe we should just let this go so other questions can be seen
@exam comment, you dont have to rely on others to make the info available, you could simply scan your certifications and post a link, that would suffice