SendString(handle, "some text...")

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by crono.

Hi there ^^

i would need a function which sends keystrokes to a handle of another window.
something like sendstring(handle, "{F1}") to open the help or so...
if you need a more specific example, just say so :)

kind regards,
Alexander Schoenfeld

Email: [url]mailto:alexander.schoenfeld@chronologic.de[/url]
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by fweil.

OK but does the Addkeyboardshortcut apply ? Because you can link a key use to a specific window ...

If you want F1 to launch Help in WindowY when you are in windowX just use addkeyboardshortcut(WindowX, #PB_Shortcut_F1, YourEventNumber) after creating WindowX and then transfer the focus to WindowY ( usewindow(WindowY) ) in the event management instructions.

Does'nt it help so ?

Francois Weil
14, rue Douer
F64100 Bayonne
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by Danilo.

>> AddKeyboardShortcut(#Window, Shortcut, EventID)

#Window is the PureBasic number of the Window,
not the windows handle - so you cant use it
for windows you have not created yourself.

You could try to use FindWindow_() and after
that send a #WM_CHAR message to the window you found.

cya,
...Danilo

(registered PureBasic user)
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by PB.

> i would need a function which sends keystrokes to a handle of another window.
> something like sendstring(handle, "{F1}") to open the help or so...

To do specifically what you requested above, open a new Notepad window and then
use this code:

Code: Select all

handle=findwindow_(0,"Untitled - Notepad") ; Gets handle of Notepad window.
PostMessage_(handle,#WM_KEYDOWN,#VK_F1,0) ; Pushes the F1 key down on it.
PostMessage_(handle,#WM_KEYUP,#VK_F1,0) ; Releases the F1 key from it.
The best part is that using PostMessage doesn't require the Notepad window
to have the focus, so it can be in the background and still have F1 pressed.

PB - Registered PureBasic Coder

Edited by - PB on 14 July 2002 23:57:29
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by crono.

hm... that sure is a way to hit F1, but what if i want notepad to write "hello world!", then simulate Ctrl+S ? :)

kind regards,
Alexander Schoenfeld

Email: [url]mailto:alexander.schoenfeld@chronologic.de[/url]
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by PB.

> hm... that sure is a way to hit F1, but what if i want notepad to
> write "hello world!", then simulate Ctrl+S ? :)

A quick search of these forums reveals this link:

viewtopic.php?t=1678


PB - Registered PureBasic Coder
Post Reply