Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Mouse for a Tablet? And different cursors?

Status
Not open for further replies.

mgh730

Programmer
Jun 12, 2002
23
US
First, I should say that I know nothing about how these mouse functions work. I have a tablet PC (compaq), which I have tried to run my programs on, but I found that the pen digitizer does not work properly.
After some experimentation, I discovered that the mouse functions return integers between 1024 and 768 no matter what screen mode I am in.
I used a simple conversion line to fix this with ratios, but I had to make my own mouse cursor to draw it in the correct place (with GET and PUT). PUT has the undesirable side effects of creating errors whenever the mouse cursor gets placed outside the screen (completely off, but also partially off). I like my implementation of the cursor so far, because it allows me to easily change cursors, but I need something better. Any suggestions?
 
There is code, to force the cusor to stay within a certain box.
 
Yes, I've tried that. But it's annoying, because I cannot have the user click on anything along a strip near the bottom of the screen of on the right of the screen.
I would like a faster way to get mouse support, probably through modifying some current assembly routines. The mouse support should allow for a mouse cursor to display on some screen (preferably 12 and 13) from hardware numbers from 0 to 1024 and 0 to 768. Can anyone write something like this for me? Perhaps something generic, that could take these numbers from the BASIC source code (screen resolution and hardware resolution).
 
Here is something for you (Vic's site and email are dead, just so you know):




Vic's QBasic Programming Tutorial

Basic Tutorial IV

MOUSE CONTROL!!!!



-----------------------------------------------------------------------------

Have you ever seen a QBasic program that uses the mouse? Have you
also wondered how you could do this easily and quickley? Well, here you
go...

First, let me explain how it is posible to access mouse control in Programm-
ing. Most likeley you have no Idea about ASM (Assembly) Programming...
I will admit that learning that can be extremely hard, but there is one
easy thing to get from it... It is something that is used in many many
DOS programming languages. It is called INTERUPTS... When you use an
interupt you are telling the computer itself to do something. A qbasic
program calls interupts all the time, only you don't know it and can't realy
controll it.
In order to use an Interupt you have to put some information into
memory and call an interupt number. If you look in a book of interupts you
would find that the mouse interupt is number 33. Before you can use this
you need to tell the computer what you want it to do with the mouse by
putting a number into memory. Here is a list of some of the numbers and
what they do. (you can find this in any INTERUPT book...)

0 RESET DRIVER AND READ STATUS
1 SHOW THE MOUSE
2 HIDE THE MOUSE
3 GIVES THE MOUSE X,Y AND BUTTON STATUS
4 SETS THE MOUSE POSITION
5 BUTTON PRESSED DATA
6 BUTTON RELEASED DATA
7 DEFINE HORIZONTAL RANGE (MAX X)
8 DEFINE VERTICLE RANGE (MAX Y)

That is all of the important ones that we will use.

In ASM turning on the mouse it would look like this...

MOV AX,1
INT 33

Thats it... Very simple, you move(MOV) 1 into the memory(AX) and call the
interupt(INT) 33 and BANG! The mouse is showed on the screen.
In Assembely this is very simple, but in QBASIC it gets a bit more involved.
You can't just use MOV and INT to call things... I will get into ASM in
QBasic in a later tutorial. For right now I just want you to copy the
code... (Very simple)...

------------------------------------------------------
Every time I use the mouse I use this program...
To copy this,

1. open up a text editor (NotePad.exe)
2. highlight the bottom code (Start where it says to...).
3. Goto Edit then Copy
4. Goto the new page in the text editor...
5. Goto Edit and then Paste.
6. Goto File and then Save_As...
7. Goto the Save As type box and change it to "All Files (*.*)"
8. Find the C:\ directory (or whatever directory you want, this example will
use the C:\ directory...)
9. Goto the File Name: box and type Mouse.Bas...
10. Click Save...
11. Get into QBasic
12. Load the c:\Mouse.bas...
13. Run the program...
14. Move and click the mouse, notice what changes...

In most cases this works. If you are using Qbasic 4.0 or higher you must
start QBasic in a DOS prompt by typing
DIRECTORY:\qb /l
But, I would REALY RECOMEND using The original QBASIC... It should be in
the same directory as QBasic but it would be called OLDQB.exe, I think...
Heres the code...




'-------------| START MOUSE PROGRAM (START COPYING HERE)--------------------

DEFINT A-Z
DECLARE SUB mouse (cx, dx, bx)
DECLARE SUB MousePointer (SW)
DIM SHARED a(9) 'Set up array for code
DEF SEG = VARSEG(a(0)) 'Get array segment (nnnn: )
' (two 8 bit)
FOR i = 0 TO 17 'length of DATA to
READ r 'read
POKE VARPTR(a(0)) + i, r 'into array/2 (nnnn:iiii) (one 8 bit)
NEXT i 'until 17

'**************************** Machine Code *********************************

DATA &HB8,&H00,&H00 : ' mov AX,[n] [Swap code-(L),(H)] in AX
DATA &H55 : ' push BP Save BP
DATA &H8B,&HEC : ' mov BP,SP Get BP to c Seg
DATA &HCD,&H33 : ' int 33 Interrupt 33
DATA &H92 : ' xchg AX,[reg] [Swap code-reg] in AX
DATA &H8B,&H5E,&H06 : ' mov BX,[BP+6] Point to (variable)
DATA &H89,&H07 : ' mov [BX],AX Put AX in (variable)
DATA &H5D : ' pop BP Restore BP
DATA &HCA,&H02,&H00 : ' ret 2 Far return

SCREEN 13
'****************************** Mouse set up ******************************

CALL MousePointer(0) 'Reset mouse and
CALL MousePointer(1) 'turn pointer on
CALL MousePointer(3) 'Get coordinates

'****************************** P R O G R A M ******************************
DO 'Put your code here
CALL mouse(cx, dx, bx)
LOCATE 1, 1: PRINT dx; cx; bx
LOOP UNTIL INKEY$ = CHR$(27) 'Stop your code here
END

SUB mouse (cx, dx, bx)

POKE VARPTR(a(4)), &H92 'Swap code,Get CX setup
CALL absolute(cx, VARPTR(a(0))) 'Run Code
' cx = cx / 8 'Adjust 25x80
POKE VARPTR(a(4)), &H91 'Swap code,Get DX setup
CALL absolute(dx, VARPTR(a(0))) 'Run Code
dx = dx / 2 'Adjust 25x80
POKE VARPTR(a(4)), &H93 'Swap code,Get BX setup
CALL absolute(bx, VARPTR(a(0))) 'Run Code

'Note :
'Remove the /8
'for graphics modes.

END SUB

SUB MousePointer (SW)

POKE VARPTR(a(0)) + 1, SW 'Swap code,Set AX = (SW)
CALL absolute(c, VARPTR(a(0))) 'Run Code

'Note:
'SW = 0-reset
'SW = 1-on
'SW = 2-off
'SW = 3-coordinates


END SUB


'-------------------| THE END (Cut here)|----------------------------------



Wow huh?!
I realy hope this works for you, I tested it out on my computer and it
works... Just remember to use the original QBASIC...

You can ignore everything except for the DO LOOP Part
This is where you will put your program...

'---------------------------------------------------------------------------

You should know what you need to do from here to work on your own mouse
project. You just use basic colide detection tecniques...

here is an example for you

In the above program bellow the

LOCATE 1, 1: PRINT dx; cx; bx

and above the

LOOP UNTIL INKEY$ = CHR$(27) 'Stop your code here

Type this in

'...

LINE (50, 50)-(80, 70), 15, B
IF bx = 1 THEN
IF dx > 50 AND dx < 80 THEN
IF cx > 50 AND cx < 70 THEN
LOCATE 2, 1: PRINT &quot;You clicked in the box&quot;
END IF
END IF
END IF

'...

What this does is draw a box that you can click in...
when you click in the box it will tell you...

----------------------------------------------------------------------------

I know this was a very short tutorial, but that is all you should really
need to start your own mouse programs. There are many QLB files out there
that do the same thing with much less code, but I prefer to use the old
fashioned way to use the mouse...
Before I leave you I should discuss a few more things...

1. If you want to turn the visible mouse off so you can draw your own
cursor at the point the mouse is at use the command

CALL MousePointer(2)
CALL MousePointer(3)

With this you are still able to tell the mouse coordinates but you do
not see the mouse. this is good if you want to make your own mouse
cursor without having to screw around with ASM and bitmaps (if you
know what I mean)...

2. If you draw something over the mouse and then move the mouse you might
notice that the mouse breaks through the background and destroys what
was drawn. To fix this you do this

CALL MousePointer(2) 'This turns the pointer off
'Draw your picture
CALL MousePointer(1) 'This turns the pointer back
CALL MousePointer(3) 'This grabs the coordinates

That should solve that problem... If it doesn't mess around with it...

3. The CALL MousePointer(x) commands

0 - Resets the mouse
1 - Turns mouse on
2 - turns mouse off
3 - gets the mouses coords...

With this in mind you shouldn't have any problems working the mouse...
Thanks for reading my tutorial, and I really hope I didn't insult your
intellegence...
---------------------------------------------------------------------------

My current E-Mail address is RADIOHANDS@AOL.com

If you are using this tutorial on your page, please leave the tutorial
exactly as it is... please don't change anything, unless its spelling
errors... Theres alot of them! I don't like using the backspace key...

The original website that these were on is


Thank you
Vic Luce
Finished
November 1
1999

If you want to be notified when a new tutorial is out..
Send An E-mail to RADIOHANDS@AOL.com
with the subject saying VQBLIST and then your E-mail address(check website)
 
mgh730,

What you need to do is wrap up the routines to draw the mouse cursor inside [tt]SUB[/tt]s. Then, you can maintain two versions of the cursor, one in [tt]PUT[/tt] format and one in a simple array that's easy for you to access (or you could even figure out how to read it directly from the [tt]PUT[/tt] array -- in [tt]SCREEN 13[/tt] this isn't too hard, though it's a bit of a challenge in [tt]SCREEN 12[/tt]). If the cursor draw would be outside of the screen boundaries, draw it yourself manually using [tt]PSET[/tt]. You can choose to avoid doing [tt]PSET[/tt] with coordinates outside of the screen boundaries if you want, but this isn't really necessary, as [tt]PSET[/tt] will automatically clip for you without generating errors.

When it comes to storing the background so that it can be restored when the cursor moves away, you can simply clip the box that is being passed to [tt]GET[/tt]. When the 'hide cursor' routine is called, it'll [tt]PUT[/tt] the [tt]GET[/tt]ted block, which can be of any size. Since in the case of the cursor overlapping the screen edge the block will have been clipped beforehand by your routine, the stored background area will be of a size that fits inside the screen for the purpose of [tt]PUT[/tt]ting the background back. Here is some nearly QB code to demonstrate the concept:
[tt]
' assuming that the PUT version of the cursor is in
' cursorPUT%(), the regular array form is in cursorPSET%(),
' and there is enough space in cursorBG%() to store the
' entire size of the cursor, whose dimensions are assumed
' to be cursorWIDTH% by cursorHEIGHT%


DIM SHARED cursorvisible%

SUB showcursor(x%, y%)
IF cursorvisible% = 0 THEN
bgWidth% = cursorWIDTH%
bgHeight% = cursorHEIGHT%

IF (x% + bgWidth% - 1) >= screenWIDTH% THEN bgWidth% = screenWIDTH% - x%
IF (y% + bgHeight% - 1) >= screenHEIGHT% THEN bgHeight% = screenHEIGHT% - y%
GET (x%, y%)-STEP(bgWidth%, bgHeight%), cursorBG%

IF (bgWidth% = cursorWIDTH%) AND (bgHeight% = cursorHEIGHT%) THEN 'no clipping was needed
PUT
(x%, y%), cursorPUT%, PSET
ELSE
FOR
i% = 0 TO bgWidth% - 1
FOR j% = 0 TO bgHeight% - 1
PSET (i% + x%, j% + y%), cursorPSET%(i%, j%)
NEXT j%
NEXT i%
END IF
END IF

cursorvisible% = cursorvisible% + 1
END SUB

SUB
hidecursor(x%, y%)
cursorvisible% = cursorvisible% - 1
IF cursorvisible% = 0 THEN
PUT
(x%, y%), cursorBG%, PSET
END IF
END SUB

SUB
movecursor(fromX%, fromY%, toX%, toY%)
savedcounter% = cursorvisible%
cursorvisible% = 1 ' ensure that the cursor is actually redrawn
hidecursor fromX%, fromY%
showcursor toX%, toY%
cursorvisible% = savedcounter%
END SUB
[/tt]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top