WinBatch Tech Support Home

Database Search

If you can't find the information using the categories below, post a question over in our WinBatch Tech Support Forum.

TechHome

Serial
plus

Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.

Receiving Mouse Button Info on Serial Port

Keywords: 	 mouse serial

Question:

I was wondering if anyone has an example of code or any ideas on how to read mouse button clicks from a serial port.

I'm basically trying to hook up a secondary mouse to either com1 or com2 to be used only as a simple two button input device. (mouse movement not required)

I want the script to recognise when one of the buttons are clicked and then to launch an application.

This is to be used in a system where a primary mouse (ps2) is connected and operating as normal....

Any ideas much appreciated.

Answer:

I would srart with the Serial exrender. Get it ro read bytes from the serial port.

With a little examination of the data you shuold be able to figure out what is going on.

Microsoft or compatible mouses (mice?) operate at 1200 baud 7 data bits,no parity and 1 stop bit. The information is sent from the mouse in bursts of 3 bytes. So examine ther data in three byte chunks.

The first byte contains button status and x,y co-ordinates. the second byte is the repeated x co-ord and third byte y co-ord.

This script does the job...

AddExtender("wwser34I.dll")


port=pComOpen("COM2",0,1200,"7N1","NONNON")

while 1
x1=pGetByte(port)
if x1==96
gosub waitforrelease
run("yourprog#1.exe","")
endif
if x1==80
gosub waitforrelease
run("yourprog#2.exe","")
endif


endwhile

pComClose(port,1) 


exit

:waitforrelease
while 1
TimeDelay(0.1)
x1=pGetByte(port)
if x1<=80 then break
endwhile
return

Article ID:   W14439
Filename:   Receiving Mouse Button Info on Serial Port.txt
File Created: 2001:03:01:15:26:30
Last Updated: 2001:03:01:15:26:30