Using FB on the internet
Using FB on the internet
I have a question about how to create a program that clicks in other programs.
Example: On the internet there's a simple game where you are with a square. On the left there is a blue dot, on the right there is a red one. You score points if you touch the blue dot, then the red one with your square, and you move your square by clicking where it should move.
How can I write a program that clicks for me, so that I don't need to sit here and click, click, click...?
Another example: The game "Avoider" on the internet is a game where you can't allow an evil dwarf to catch your mouse. Is there a way to write a program that checks where the dwarf is, and if it sees the dwarf coming towards the mouse, moves the mouse away?
Any help is appreciated!
-Tusike
Example: On the internet there's a simple game where you are with a square. On the left there is a blue dot, on the right there is a red one. You score points if you touch the blue dot, then the red one with your square, and you move your square by clicking where it should move.
How can I write a program that clicks for me, so that I don't need to sit here and click, click, click...?
Another example: The game "Avoider" on the internet is a game where you can't allow an evil dwarf to catch your mouse. Is there a way to write a program that checks where the dwarf is, and if it sees the dwarf coming towards the mouse, moves the mouse away?
Any help is appreciated!
-Tusike
-
- Posts: 2655
- Joined: Aug 28, 2008 10:54
- Location: new york
It sounds like you're trying to play the game without actually playing the game, in which case, my best advice would be to find a more fun game that is actually worth your time to play. But...
To automate repetitive tasks in such a manner requires first a solid knowledge of programming for your OS, as it would require a full web browser style program which.
So question one: What are you running under? Dos, Linux, or Windows?
To automate repetitive tasks in such a manner requires first a solid knowledge of programming for your OS, as it would require a full web browser style program which.
So question one: What are you running under? Dos, Linux, or Windows?
-
- Posts: 2655
- Joined: Aug 28, 2008 10:54
- Location: new york
I'm sure it's possible. But you'd have to interface through your browser I'd image. So you'd need to send all the data through windows. Ask in the windows forum and someone will be able to help you.
It has to know where to click right?
So it has to read data from the browser, and route click calls through the browser... It wouldn't be as simple as sending numbers back and forth.
It has to know where to click right?
So it has to read data from the browser, and route click calls through the browser... It wouldn't be as simple as sending numbers back and forth.
I hoped it might be a little bit more simpler, and someone here would have the solution. I'm pretty sure some people here have created programs similar to the kind I'm trying to do. I'll try Google and the windows forum.
Thanks for your help!
If anybody has any other suggestions, please tell me.
-Tusike
EDIT: Maybe it would be a bit simpler if I first found out how to use a program to open e.g. notepad, and every 5 seconds write the time inside. And I would be able to sit back, and watch how every 5 seconds the time appears on the notepad. Is that possible?
Thanks for your help!
If anybody has any other suggestions, please tell me.
-Tusike
EDIT: Maybe it would be a bit simpler if I first found out how to use a program to open e.g. notepad, and every 5 seconds write the time inside. And I would be able to sit back, and watch how every 5 seconds the time appears on the notepad. Is that possible?
You can send faux mouse messages to the window using SendMessageA. You will first need to find the hWnd of the window to send the messages to. Also, you may run into some problems if you try this using VISTA. Not sure but you should keep that in mind. Anyway, the process will look like this....
Get handle (hWnd) of Internet explorer window
Do
Send faux mouse click messages
Loop until you are bored.
Check the MSDN for how to use SendMessage
-Vince
Get handle (hWnd) of Internet explorer window
Do
Send faux mouse click messages
Loop until you are bored.
Check the MSDN for how to use SendMessage
-Vince
-
- Posts: 2655
- Joined: Aug 28, 2008 10:54
- Location: new york
Firstly, you want to make certain the you have the latest version of the compiler which is 0.20.0. Second then, you should see in your main freebasic directory that there are several example files for dealing with windows.
Then you want to play around with the files and develop a plan of attack. How am I going to determine the location of the ball? How am I going to send the mouse click?
At the very least the answers will require an intermediate knowledge of the Windows API. If you were using the FBgfx, this would be a snap, but the theory is the same. Scan the window for the ball's color and determine where the mouse click should be sent based on its color being distinct from every other.
Here is a good place to start:
http://www.freebasic.net/wiki/wikka.php ... ssageIntro
When your question is more specific and less general people will be able to help you better, and also you may have better luck in the Windows forum where Windows programmers congregate to discuss the API.
Then you want to play around with the files and develop a plan of attack. How am I going to determine the location of the ball? How am I going to send the mouse click?
At the very least the answers will require an intermediate knowledge of the Windows API. If you were using the FBgfx, this would be a snap, but the theory is the same. Scan the window for the ball's color and determine where the mouse click should be sent based on its color being distinct from every other.
Here is a good place to start:
http://www.freebasic.net/wiki/wikka.php ... ssageIntro
When your question is more specific and less general people will be able to help you better, and also you may have better luck in the Windows forum where Windows programmers congregate to discuss the API.
http://msdn.microsoft.com/en-us/library/ms646260.aspxTusike wrote:Where can i check how this mouse_event works?
-Tusike
The Internet is your friend. Don't be afraid to use it. I found this by searching yahoo for 'mouse_event' and 'MSDN'.
-Vince
After some experimenting, I managed to write a program that moves the mouse on the screen by itself.
However, this was in a SCREEN 20 window. I still couldn't manage to have the mouse move in another window.
Thanks for all the help so far!
-Tusike
The code:
However, this was in a SCREEN 20 window. I still couldn't manage to have the mouse move in another window.
Thanks for all the help so far!
-Tusike
The code:
Code: Select all
#include "windows.bi"
SCREEN 20, , , 1
DECLARE SUB relativemove() 'relative or absolue mouse movement
DECLARE SUB absolutemove()
DIM SHARED AS DWORD dwflags, dx, dy, dwdata 'from the MSDN guide
DIM SHARED AS ULONG_PTR dwExtrainfo
DIM SHARED AS INTEGER mx, my 'for determining x and y coordanites for the mouse
dwflags = MOUSEEVENTF_ABSOLUTE + MOUSEEVENTF_MOVE 'first, the mouse is moved and it's absolute, so we can set it to 0, 0
dx = 0
dy = 0
dwdata = 0
dwExtrainfo = GetMessageExtraInfo 'I don't know what this is. MSDN said so...
mouse_event(dwflags, dx, dy, dwdata, dwExtrainfo)
'relativemove 'choose if you want to see relative or absolute movement
absolutemove
SUB relativemove()
dwflags = MOUSEEVENTF_MOVE 'we don't need to add MOUSEEVENTF_ABSOLUTE here, since it's relative
DO
getmouse(mx, my)
IF mx >= 1023 THEN dx = -1 'If we reach the end of the screen, we change the relative movement
IF mx <= 0 THEN dx = 1
IF my >= 767 THEN dy = -1
IF my <= 0 THEN dy = 1
dwExtrainfo = GetMessageExtraInfo
mouse_event(dwflags, dx, dy, dwdata, dwExtrainfo)
SLEEP 1
LOOP WHILE INKEY = ""
SYSTEM
END SUB
SUB absolutemove()
dx = 0
dy = 0
dwflags = MOUSEEVENTF_ABSOLUTE + MOUSEEVENTF_MOVE
DIM AS INTEGER iy = 1, ix = 1
DO
getmouse(mx, my)
IF mx >= 1020 THEN ix = -1
IF mx <= 0 THEN ix = 1
IF my >= 765 THEN iy = -1
IF my <= 0 THEN iy = 1
dx += 64 * ix
dy += 85 * iy 'absolute movement has 65535 locations for the mouse on each axis
'that divided by 1024 and 768 gives 64 and 85
dwExtrainfo = GetMessageExtraInfo
mouse_event(dwflags, dx, dy, dwdata, dwExtrainfo)
SLEEP 1
LOOP WHILE INKEY = ""
SYSTEM
END SUB
SYSTEM
-
- Posts: 1186
- Joined: May 08, 2006 21:58
- Location: Crewe, England
-
- Posts: 2655
- Joined: Aug 28, 2008 10:54
- Location: new york
I noticed you were still using getmouse. Getmouse will only work on the fbgfx graphics screen. Once it runs off the black screen you can kiss it goodbye, it's out of range.
Use this to record off the graphics screen. I don't know much about windows programming, but I do run windows, and often I'll need the mouse position to record no matter where it is relative to the screen. So I think you'll need to replace getmouse with this.
rb
Code: Select all
dim as point mousepos
GetCursorPos(@mousepos)
mx = mousepos.x
my = mousepos.y
rb