Manuel PortaNum

Rebol3 WinExtension - version 0.6.0

        mis à jour le 6-Nov-2010

index

Introduction
Try it
Documentation
general commands
applications commands
messages to a given window
sendkeys
MCI commands

Introduction

WinExtension - version 0.6.0 J. Colineau (alias Jocko)

This extension for R3 gives a simple access to some entries of the win API. We have kept as few parameters as possible, in order to stay in the "KISS" spirit (KISS = Keep It Simple and Smart) of REBOL.

- This extension allows to launch windows applications.

- It allows also to send messages or emulate keystrokes to a windows application.

- At last, it offers simple MCI (Media Control Interface) interfacing for easily playing sound or video files.

I originally collected these functions for improving access to the computer to disabled people. Later, I used them for automation of software not designed for repetitive tasks.

Warnings: this extension is compatible with R3 Alpha (version A110+) The extension specs being not finalized, we may encounter compatibility problems with future R3 versions. It has been tested under XP.

Use of system commands is done at your own risks. The keyboard emulation, particularly, may lead to unwanted commands, and damage files. One should check carefully the scripts before executing them.

The sendkeys function uses CKeystrokeEngine by Mustafa Demirhan

http://www.codeproject.com/KB/dialog/keystroke.aspx

NB: we have introduced a modification in order to be compatible with DELL laptops the flag KEYEVENTF_EXTENDEDKEY was sent systematically, even for normal keys, which was, to my opinion, a bug. The consequence could be the non-operation of a small number of special keys.

Try it

Note - the files have a suffix .r3, in order to launch them with R3.exe (provided you have done the right launch program association)

quick start sendkeys demo MCI demo

executable and examples

Documentation

general commands

w-version  ; returns extension version
w-sound        ; emission of a message beep

w-beep         ; emission of a system beep

applications commands

w-launch <app_name> : launches an application
   <app_name>: name (and optionally path) of the exe

w-launch-dir <app_name> <execution_directory> : launches an application in a given directory
   <app_name>: name (and optionally path) of the exe
   <execution_directory> : directory of execution

w-playsound <file> : plays asynchronously the given file

w-minimize-all : minimizes all the open windows, and shows the desktop

w-restore-all : restores all the minimized windows

examples :

w-launch "calc.exe"
w-launch-dir "notepad.exe" "c:\temp" ... does not work properly up to now ...
w-playsound "test.wav"

messages to a given window

w-find-window <window_title>
   <window_title>: title of the window, or part of it (case sensitive)
   returns the handle of the window

w-find-window-cl <window_title> <window_classname>
   <window_title>: title of the window, or part of it (case sensitive)
   <window_classname>: classname of the window (case sensitive) or empty string ("")
   returns the handle of the window

w-close <window_handle>: closes an application by closing the main window
   <window_handle>: handle of the window
   w-message <window_handle> <message_id>  sends a windows-type message to a given window
   <window_handle>: handle of the window

<message_id>: decimal value of the message

example :

hCalc: w-find-window "Calc"
hCalc: w-find-window-cl "Calc" "SciCalc"
w-message hCalc "16"
(nb: 16 is the decimal for WM_CLOSE = 0x0010)

sendkeys

w-sendkeys <window_handle> <key_sequence> : sends a sequence of virtual keys to the window
   <window_handle>: handle of the window
   <key_sequence>: key sequence

example :

hNotepad: w-find-window "essai.txt"
w-sendkeys hNotepad "<F5>"

details of the sendkey command :

(from the CKeystrokeEngine documentation by Mustafa Demirhan)

http://www.codeproject.com/KB/dialog/keystroke.aspx

A simple expression in the CKeystrokeEngine format resembles to this:

Hello World!<ENTER><REPEAT 10>REBOL is fantastic !<ENTER><END_REPEAT>

All the special keys are surrounded by '<' and '>'.

For instance, to simulate an Enter key, vous will use .

Or, to press the Shift key, use . Here are other examples:

- To send Ctrl+A, use A

- To send Alt+F4, use

- To send Ctrl+Alt+Shift+A, use A

You can also use , , and .

To hold down the Shift key, and many other keys, use your keys here .

You can also use , , , and .

To add a delay, use where xxx is the delay in miliseconds.

For instance, sets a 1.5 seconds delay.

To repeat a sequence 100 times, use your keys here .

NB: imbricated repetitions are not supported.

MCI commands

w-mci : sends the MCI string to the system

returns an acknoledgement or an error message

for a complete list of the mci commands, see Multimedia Programming Interface specifications see also http://msdn.microsoft.com/en-us/library/ms712587%28VS.85%29.aspx

depending of the hardware, and windows version, some commands may not be executed

here are several examples:

w-mci "play cdaudio"   : reads the audio-CD in the current CD-drive
w-mci "stop cdaudio"   : stops readout (also: pause, resume ...)
w-mci "play butterfly.mpg"    : shows a movie
w-mci "play butterfly.mpg fullscreen"    : shows a movie in full screen 
w-mci "play hilander.mp3"  : plays an audio file

other commands to test :

play a video in an application window:

w-mci "open essai.avi Type avivideo alias video1 parent <hwnd> style &H40000000"

record with the default windows recorder, and playback:

w-mci "open new type waveaudio alias capture"
w-mci "status capture mode"
w-mci "set capture bitspersample 16"
w-mci "record capture"
(wait 5)
w-mci "save capture test.wav"
w-mci "close capture"
(wait 1)
w-mci "play test.wav"

Valid HTML 4.01 Transitional

copyright J.Colineau - 6-Nov-2010