Results 1 to 20 of 20

Thread: [VB6] how can i make a click recorder...?

  1. #1

    Thread Starter
    New Member
    Join Date
    Jan 2006
    Posts
    10

    Arrow [VB6] how can i make a click recorder...?

    well the question is in the title, but i would like to describe what i want.

    i want to make a program like Ghostmouse that records clcik of your mose and plays them back.

    this is also for my game client.

  2. #2
    Frenzied Member the182guy's Avatar
    Join Date
    Nov 2005
    Location
    Cheshire, UK
    Posts
    1,473

    Re: [VB6] how can i make a click recorder...?

    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
    Chris

  3. #3

    Thread Starter
    New Member
    Join Date
    Jan 2006
    Posts
    10

    Question Re: [VB6] how can i make a click recorder...?

    most pplz may be surprised...but that makes sense to me
    im a 12 year old, iv been using VB for about a month...and i learn best from example code.

    so what im askin is, could you maybe compose an example code for me plz?

  4. #4
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649

    Re: [VB6] how can i make a click recorder...?

    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.

  5. #5

    Thread Starter
    New Member
    Join Date
    Jan 2006
    Posts
    10

    Question Re: [VB6] how can i make a click recorder...?

    Quote Originally Posted by Joacim Andersson
    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.
    ok that one didnt make (much) sense to me....

  6. #6
    Frenzied Member the182guy's Avatar
    Join Date
    Nov 2005
    Location
    Cheshire, UK
    Posts
    1,473

    Re: [VB6] how can i make a click recorder...?

    @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!

    I cant remember the cursor APIs off the top of my head, this would be better in the API forum. You will get tons of replies from the API pros.

    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.

    Good luck
    Chris

  7. #7

    Thread Starter
    New Member
    Join Date
    Jan 2006
    Posts
    10

    Exclamation Re: [VB6] how can i make a click recorder...?

    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

  8. #8
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649

    Re: [VB6] how can i make a click recorder...?

    Quote Originally Posted by the182guy
    @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:
    1. Private Declare Function GetCursorPos Lib "user32.dll" ( _
    2.     ByRef lpPoint As POINTAPI _
    3. ) As Long
    4.  
    5. Private Declare Function SetCursorPos Lib "user32.dll" ( _
    6.     ByVal x As Long, _
    7.     ByVal y As Long _
    8. ) As Long
    9.  
    10. Private Type POINTAPI
    11.     x As Long
    12.     y As Long
    13. End Type
    To get the coordinates of the mouse you would then use code simular to this:
    VB Code:
    1. Dim p As POINTAPI
    2. Call GetCursorPos(p)
    3. 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...

  9. #9

    Thread Starter
    New Member
    Join Date
    Jan 2006
    Posts
    10

    Talking Re: [VB6] how can i make a click recorder...?

    thanks! ill figure how to use the code and stuff...and itl help me learn the vb laguage...

  10. #10
    Hyperactive Member guyvdn's Avatar
    Join Date
    Oct 2002
    Location
    Belgium
    Posts
    336

    Re: [VB6] how can i make a click recorder...?

    You can use the mouse_event api to simulate a click event after you set the mouseposition with the SetCursorPos function.

    VB Code:
    1. 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)
    2. Const MOUSEEVENTF_LEFTDOWN = &H2
    3. Const MOUSEEVENTF_LEFTUP = &H4
    4. Const MOUSEEVENTF_MIDDLEDOWN = &H20
    5. Const MOUSEEVENTF_MIDDLEUP = &H40
    6. Const MOUSEEVENTF_MOVE = &H1
    7. Const MOUSEEVENTF_ABSOLUTE = &H8000
    8. Const MOUSEEVENTF_RIGHTDOWN = &H8
    9. Const MOUSEEVENTF_RIGHTUP = &H10
    10.  
    11. 'Simulate a mouseclick on the cursor's position
    12. 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

  11. #11
    Frenzied Member the182guy's Avatar
    Join Date
    Nov 2005
    Location
    Cheshire, UK
    Posts
    1,473

    Re: [VB6] how can i make a click recorder...?

    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
    Chris

  12. #12
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649

    Re: [VB6] how can i make a click recorder...?

    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:
    1. Dim mice As CMouse
    2. Set mice = New CMouse
    3. MsgBox "The current position of the mouse is " & mice.X & "," & mice.Y
    4. 'Move the mouse
    5. mice.MoveTo 10, 25
    6. 'The above could also been done by changing the X and Y properties but
    7. 'in that case would have required these two calls:
    8. '  mice.X = 10
    9. '  mice.Y = 25
    10. 'Now let us click at the current position
    11. mice.Click
    EDIT: Sorry forgot the attachment
    Attached Files Attached Files
    Last edited by Joacim Andersson; Feb 17th, 2006 at 05:58 PM.

  13. #13
    Frenzied Member the182guy's Avatar
    Join Date
    Nov 2005
    Location
    Cheshire, UK
    Posts
    1,473

    Re: [VB6] how can i make a click recorder...?

    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
    Chris

  14. #14
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649

    Re: [VB6] how can i make a click recorder...?

    Quote Originally Posted by the182guy
    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.

  15. #15
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649

    Re: [VB6] how can i make a click recorder...?

    Quote Originally Posted by the182guy
    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.

  16. #16
    Frenzied Member the182guy's Avatar
    Join Date
    Nov 2005
    Location
    Cheshire, UK
    Posts
    1,473

    Re: [VB6] how can i make a click recorder...?

    Quote Originally Posted by Joacim Andersson
    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
    Chris

  17. #17
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649

    Re: [VB6] how can i make a click recorder...?

    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 .

  18. #18
    Frenzied Member the182guy's Avatar
    Join Date
    Nov 2005
    Location
    Cheshire, UK
    Posts
    1,473

    Re: [VB6] how can i make a click recorder...?

    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
    Chris

  19. #19
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649

    Re: [VB6] how can i make a click recorder...?

    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.

  20. #20
    Frenzied Member the182guy's Avatar
    Join Date
    Nov 2005
    Location
    Cheshire, UK
    Posts
    1,473

    Re: [VB6] how can i make a click recorder...?

    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
    Chris

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width