Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DarkBASIC Professional Discussion / Controlling another window using darkbasic

Author
Message
slade
22
Years of Service
User Offline
Joined: 14th Feb 2003
Location:
Posted: 14th Feb 2003 14:30
Hi, im trying to find out if there is any way for dark basic to send commands to other windows, ie: mouse & keyboard events. At the moment im using a seperate macro program to control the window, launched & controlled from within dbasic. Theres no actual native commands to do this and the way im using at the moment is very inefficient, basically a bodge job Any help, ideas appreciated, ty.
spooky
22
Years of Service
User Offline
Joined: 30th Aug 2002
Location: United Kingdom
Posted: 14th Feb 2003 14:36
Just wait for MrTAToad to do a plug-in.

He likes doing them.

I'm sure he can link to some sort of windows library to do what you want.

I love it when a plan comes together
slade
22
Years of Service
User Offline
Joined: 14th Feb 2003
Location:
Posted: 14th Feb 2003 14:49
That would be excellent It just requires someone with some windows internal knowledge. All thats needed is to send keystroke and mouse move/click events, nothing too complicated. (i hope!)

MrTAToad
22
Years of Service
User Offline
Joined: 26th Aug 2002
Location: United Kingdom
Posted: 14th Feb 2003 16:04
Sending keystrokes/mouse presses to a window is a real pain. I'll see what I can do, although no guarantees...

Good news everyone! I really am THAT good...
http://www.nickk.nildram.co.uk/ for great plug-ins - oh my, yes!
MrTAToad
22
Years of Service
User Offline
Joined: 26th Aug 2002
Location: United Kingdom
Posted: 14th Feb 2003 16:13
And what OS are you using ?

Good news everyone! I really am THAT good...
http://www.nickk.nildram.co.uk/ for great plug-ins - oh my, yes!
slade
22
Years of Service
User Offline
Joined: 14th Feb 2003
Location:
Posted: 14th Feb 2003 16:25
XP PRO sp1

Thx for having a go anyway..

MrTAToad
22
Years of Service
User Offline
Joined: 26th Aug 2002
Location: United Kingdom
Posted: 14th Feb 2003 16:33
Thats okay - the window you want to send the data to unfortunately needs to be running and currently active (ie at the front of everything else...)

That parts easy enough, but it could obscure any DarkBasic stuff...

Good news everyone! I really am THAT good...
http://www.nickk.nildram.co.uk/ for great plug-ins - oh my, yes!
MrTAToad
22
Years of Service
User Offline
Joined: 26th Aug 2002
Location: United Kingdom
Posted: 14th Feb 2003 16:37
Aside from that, it looks easier that I thought it would be...

Good news everyone! I really am THAT good...
http://www.nickk.nildram.co.uk/ for great plug-ins - oh my, yes!
slade
22
Years of Service
User Offline
Joined: 14th Feb 2003
Location:
Posted: 14th Feb 2003 16:44
Thats no problem, i dont need to look at the darkbasic window, at the moment i have a little .exe macro that forces the focus on the window i want to work with.

MrTAToad
22
Years of Service
User Offline
Joined: 26th Aug 2002
Location: United Kingdom
Posted: 14th Feb 2003 20:33
Okay - its coming on very well, very well indeed!

Good news everyone! I really am THAT good...
http://www.nickk.nildram.co.uk/ for great plug-ins - oh my, yes!
slade
22
Years of Service
User Offline
Joined: 14th Feb 2003
Location:
Posted: 14th Feb 2003 21:40
Have to say im impressed i didnt expect to get a response straight away...

IanM
Retired Moderator
22
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 14th Feb 2003 22:54
You can use an existing system DLL:



The hard bit (I hope what MrTAToad is working on) is to send meaningful messages for keypresses, mouse movements, and mouse clicks.

Because of the way windows has evolved, sending detailed messages is not easy. Everything except the message type is encoded within a total of 6 bytes.
MrTAToad
22
Years of Service
User Offline
Joined: 26th Aug 2002
Location: United Kingdom
Posted: 14th Feb 2003 23:24
I'll be sending an e-mail soonish with a demo of keyboard control over a notepad window (all the keyboard commands are present).

There are two cravets :

1. You can't send lower-case characters to another window/program per se, the case is unfortunately controlled by the CAPS LOCK key - there may or may not be a way around this. You can toggle the NUM LOCK, CAPS LOCK and SCROLL LOCK lights on and off...
Oh, can you can grab the screen too.
2. The controls for sending the computer to sleep will be ignored. Can't have you using this plug-in for viruses, can we ?

Good news everyone! I really am THAT good...
http://www.nickk.nildram.co.uk/ for great plug-ins - oh my, yes!
IanM
Retired Moderator
22
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 14th Feb 2003 23:48
You should be able to send any character you want using a WM_CHAR message...
MrTAToad
22
Years of Service
User Offline
Joined: 26th Aug 2002
Location: United Kingdom
Posted: 14th Feb 2003 23:52
No, that way isn't reliable...

Ah, Slade doesn't have an e-mail address. Looks like it'll be a web-site update then.

Good news everyone! I really am THAT good...
http://www.nickk.nildram.co.uk/ for great plug-ins - oh my, yes!
slade
22
Years of Service
User Offline
Joined: 14th Feb 2003
Location:
Posted: 14th Feb 2003 23:54
Im not familiar with windows enviroment programming. ie. dealing with dll`s/handles etc etc so while i could use user32.dll id have to learn a lot of windows internal workings from scratch...

IanM
Retired Moderator
22
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 15th Feb 2003 00:21
How about using this for shift?



Then post your keydown/up messages, and this to switch shift off:


You can do the same with the control key (VK_CONTROL).

Hope that gives you a direction to head towards
MrTAToad
22
Years of Service
User Offline
Joined: 26th Aug 2002
Location: United Kingdom
Posted: 15th Feb 2003 00:27
Yes, might be an idea to resolve the case issue.

I'll see what Slade thinks of the beta before adding to it, which is now availiable from my web site.

The test program is currently :



With this you get Notepad to open up the help window, and the Find window...

Good news everyone! I really am THAT good...
http://www.nickk.nildram.co.uk/ for great plug-ins - oh my, yes!
IanM
Retired Moderator
22
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 15th Feb 2003 00:41
Hey, let's not make things too easy for him...
slade
22
Years of Service
User Offline
Joined: 14th Feb 2003
Location:
Posted: 15th Feb 2003 00:55
lol at Ian, well it cant get much easier than that. Worked 1st time, replaced my macro calls for text (although theres not much key control, mostly its mouse) with sendstringtext() and it works spot on

For my purposes, the case issue isnt a problem, dosent matter what case its in, although i know how these little niggling problems can be annoying.

ty, simple mouse positioning and clicking and it will be perfect (btw mouse positioning has to be window relative which was a pain to do with the macro proggys so dont know how easy it is)

MrTAToad
22
Years of Service
User Offline
Joined: 26th Aug 2002
Location: United Kingdom
Posted: 15th Feb 2003 08:06
Yes, I'll see what I can do with the mouse later.
Need to fix the NumLock/ScrollLock/CapsLock function to allow switch on or off, instead of toggling.

Good news everyone! I really am THAT good...
http://www.nickk.nildram.co.uk/ for great plug-ins - oh my, yes!
MrTAToad
22
Years of Service
User Offline
Joined: 26th Aug 2002
Location: United Kingdom
Posted: 15th Feb 2003 08:07
And the other thing is to make it work with 95/98...

Good news everyone! I really am THAT good...
http://www.nickk.nildram.co.uk/ for great plug-ins - oh my, yes!
IanM
Retired Moderator
22
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 15th Feb 2003 13:23
slade: I'd expect nothing less from MrTAToad - he is THAT good
slade
22
Years of Service
User Offline
Joined: 14th Feb 2003
Location:
Posted: 15th Feb 2003 13:28
hey, can i help being impressed, get darkbasic, get stuck, 1st post on forum... problem halfway being solved

(The mouse bit is the main part tho, i cant help thinking thats not gonna be so easy.. better hope he really is THAT good )

MrTAToad
22
Years of Service
User Offline
Joined: 26th Aug 2002
Location: United Kingdom
Posted: 15th Feb 2003 13:39
Its going to be tricky for mouse movement - according to the documentation, its all relative to the screen and not the window...

Good news everyone! I really am THAT good...
http://www.nickk.nildram.co.uk/ for great plug-ins - oh my, yes!
slade
22
Years of Service
User Offline
Joined: 14th Feb 2003
Location:
Posted: 15th Feb 2003 13:50
The macro proggy im using is "tasker"
www.vista-software.com
It allows you to compile macros into small .exe chunks which i was calling from darkbasic. The nice thing about it was that it could be screen or window relative, theres a very simple script language built in which worked relative to the active window, or you could record windows messages (like ianm was talking about) and these were screen relative.
If screen relative is simple to implement compared to windowed i can live with that, just means have to maximise the window im working on.

IanM
Retired Moderator
22
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 15th Feb 2003 13:58
Hint: ClientToScreen(HWND,LPPOINT)
slade
22
Years of Service
User Offline
Joined: 14th Feb 2003
Location:
Posted: 15th Feb 2003 14:03
So i guess you just get a screen coordinate of the active window and offset your coordinates so they are then screen relative, and make sure its checked each time incase the window is moved...

IanM
Retired Moderator
22
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 15th Feb 2003 14:17
The idea is that you have a coord within the controlled window that you wish to move the mouse to, pass that into the ClientToScreen() function and it converts it to screen coordinates. You can then pass a movemouse/click event to the controlled window with this coordinate.
MrTAToad
22
Years of Service
User Offline
Joined: 26th Aug 2002
Location: United Kingdom
Posted: 15th Feb 2003 14:51
Unforunately that doesn't seem to work...

Good news everyone! I really am THAT good...
http://www.nickk.nildram.co.uk/ for great plug-ins - oh my, yes!
MrTAToad
22
Years of Service
User Offline
Joined: 26th Aug 2002
Location: United Kingdom
Posted: 15th Feb 2003 14:58
...I'm having to multiply the screen X & Y coordinates by 64 for some reason...

Good news everyone! I really am THAT good...
http://www.nickk.nildram.co.uk/ for great plug-ins - oh my, yes!
MrTAToad
22
Years of Service
User Offline
Joined: 26th Aug 2002
Location: United Kingdom
Posted: 15th Feb 2003 15:04
I presume at the moment I'm not taking into account pixel depth...

Good news everyone! I really am THAT good...
http://www.nickk.nildram.co.uk/ for great plug-ins - oh my, yes!
MrTAToad
22
Years of Service
User Offline
Joined: 26th Aug 2002
Location: United Kingdom
Posted: 15th Feb 2003 15:36
...doesn't help that the mouse needs normalised absolute coordinates...

Good news everyone! I really am THAT good...
http://www.nickk.nildram.co.uk/ for great plug-ins - oh my, yes!
slade
22
Years of Service
User Offline
Joined: 14th Feb 2003
Location:
Posted: 15th Feb 2003 15:48
Sounds like your having fun...

MrTAToad
22
Years of Service
User Offline
Joined: 26th Aug 2002
Location: United Kingdom
Posted: 15th Feb 2003 15:56
Got it sorted...

It essentially boils down to :



Now I just need to decide how to find the window (dont trust FindWindow...)

Good news everyone! I really am THAT good...
http://www.nickk.nildram.co.uk/ for great plug-ins - oh my, yes!
slade
22
Years of Service
User Offline
Joined: 14th Feb 2003
Location:
Posted: 15th Feb 2003 17:45
Quick question: when you send the printscreen where does the screen data go?

MrTAToad
22
Years of Service
User Offline
Joined: 26th Aug 2002
Location: United Kingdom
Posted: 15th Feb 2003 18:14
The clipboard.

Good news everyone! I really am THAT good...
http://www.nickk.nildram.co.uk/ for great plug-ins - oh my, yes!
slade
22
Years of Service
User Offline
Joined: 14th Feb 2003
Location:
Posted: 15th Feb 2003 18:25
i knew that, or at least i should have >.<

IanM
Retired Moderator
22
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 15th Feb 2003 18:38
If the window you want to control is the active window, you can use GetActiveWindow(). Or use WindowFromPoint().

Or enumerate all of the windows and let slade work out which one he wants - by name or classname etc.
slade
22
Years of Service
User Offline
Joined: 14th Feb 2003
Location:
Posted: 15th Feb 2003 18:50
Can you force a window with specified name the active window easily? Dont need to find all windows then, just focus the named window and return successful true/false?

MrTAToad
22
Years of Service
User Offline
Joined: 26th Aug 2002
Location: United Kingdom
Posted: 15th Feb 2003 21:21
If you want to bring a named window to the front, then thats easy enough. I direct all mouse functions to the current foreground window...

The trouble with finding windows is that there can be more than 1 with the same name.

Good news everyone! I really am THAT good...
http://www.nickk.nildram.co.uk/ for great plug-ins - oh my, yes!
MrTAToad
22
Years of Service
User Offline
Joined: 26th Aug 2002
Location: United Kingdom
Posted: 15th Feb 2003 22:19
The program has been updated & is availiable from my web site as usual.

I'll put in a enumeration routine later.

Good news everyone! I really am THAT good...
http://www.nickk.nildram.co.uk/ for great plug-ins - oh my, yes!
slade
22
Years of Service
User Offline
Joined: 14th Feb 2003
Location:
Posted: 15th Feb 2003 23:13
Tried downloading but still 1.0.0.1 version??

MrTAToad
22
Years of Service
User Offline
Joined: 26th Aug 2002
Location: United Kingdom
Posted: 15th Feb 2003 23:34
No, should be 1.0.0.2

Good news everyone! I really am THAT good...
http://www.nickk.nildram.co.uk/ for great plug-ins - oh my, yes!
slade
22
Years of Service
User Offline
Joined: 14th Feb 2003
Location:
Posted: 16th Feb 2003 02:38
really strange, i tried downloading it loads of times and only got 1.0.0.1, ive just tried again and it was 1.0.0.2 ??? Maybe your web host was caching the old version... Trying it out now, ill let you know tomorrow.... looks good tho thx

MrTAToad
22
Years of Service
User Offline
Joined: 26th Aug 2002
Location: United Kingdom
Posted: 16th Feb 2003 10:03
It could be IE cache you know, or perhaps you were downloading as I was uploading...

Good news everyone! I really am THAT good...
http://www.nickk.nildram.co.uk/ for great plug-ins - oh my, yes!
slade
22
Years of Service
User Offline
Joined: 14th Feb 2003
Location:
Posted: 16th Feb 2003 13:06
Well its just the job! Virtually converted all the cumbersone macro exes and it works fine, much more elegant solution. Just 1 question: how do i get the screen data from the clipboard, dark basic only has a command write to it, not read.

Thx again for takin the time to help, hopefully other ppl with find it useful too

MrTAToad
22
Years of Service
User Offline
Joined: 26th Aug 2002
Location: United Kingdom
Posted: 16th Feb 2003 14:18
There is a clipboard command, but I doubt it will grab graphics...

Good news everyone! I really am THAT good...
http://www.nickk.nildram.co.uk/ for great plug-ins - oh my, yes!
IanM
Retired Moderator
22
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 16th Feb 2003 14:47
strings only - GET CLIPBOARD$()

Another plugin?
GET CLIPBOARD SIZE()
COPY CLIPBOARD TO MEMORY ptr
slade
22
Years of Service
User Offline
Joined: 14th Feb 2003
Location:
Posted: 16th Feb 2003 14:54
hehe hes gonna end up writing the whole program... Yea i meant to say theres no clipboard read except for strings. Theres a function to create a screenshot in the game but its the pause-break key, cant send that at the momemnt... Can i sent a code using one of the existing plugin commands, or does it have to be a new one? The printscreen dosent handle this properly anyway because the screen is 256 colours and it comes out screwed up.

Login to post a reply

Server time is: 2025-05-18 05:42:36
Your offset time is: 2025-05-18 05:42:36