Author Topic: How to move the mouse cursor with the keyboard  (Read 13266 times)

majid1605

  • Guest
How to move the mouse cursor with the keyboard
« on: January 11, 2013, 09:20:17 AM »
What is the problem my code?

Code: [Select]
stacksg segment para stack 'stack'

stacksg ends

datasg segment para 'data'

  msg db "A. $", 0
datasg  ends

codes segment para 'code'
assume ss:stacksg, ds:datasg, cs:codes
   mov ax, datasg
   mov ds, ax
    ;------------ ur programm
   

mov al,4
mov bh,0
int 10h

mov bh,0
mov bl,1001b
mov ah,0Bh
int 10h

mov ax,0
int 33h

mov ax,01h
int 33h

;mov dx,101h
;mov cx,161h
lable1:

mov ah,10h
int 16h
cmp al,48h ;up key (arrow) 24dec
je lable
cmp al,50h ;Down key (arrow) 24dec
je lable2


lable:
mov ax,03h
int 33h

mov ax,04h
int 33h
dec dx
cmp dx,0
jne lable1

lable2:
mov ax,03h
int 33h

mov ax,04h
int 33h
inc dx
cmp dx,199h
jne lable1

    ;------------ end of program
    mov ax, 4c00h
    int 21h



codes ends
     end

jj2007

  • Member
  • *****
  • Posts: 13957
  • Assembly is fun ;-)
    • MasmBasic
Re: How to move the mouse cursor with the keyboard
« Reply #1 on: January 11, 2013, 10:06:51 AM »
I get a full blue screen with a big mouse cursor (arrow to the upper left). What is it supposed to do, what is your specific problem?

nidud

  • Member
  • *****
  • Posts: 2388
    • https://github.com/nidud/asmc
Re: How to move the mouse cursor with the keyboard
« Reply #2 on: January 11, 2013, 10:14:04 AM »
deleted
« Last Edit: February 25, 2022, 06:11:11 AM by nidud »

dedndave

  • Member
  • *****
  • Posts: 8828
  • Still using Abacus 2.0
    • DednDave
Re: How to move the mouse cursor with the keyboard
« Reply #3 on: January 11, 2013, 10:42:33 AM »
in your code, you have an empty stack segment
i guess that means no stack space ?

it's also helpful to use the model and segment "shortcut" directives...
Code: [Select]
        .MODEL  Small
        .386
        .STACK  1024
        OPTION  CaseMap:None

;####################################################################################

        .DATA

s$Hello db 'Hello World!',0Dh,0Ah,24h

;************************************************************************************

;        .DATA?

;####################################################################################

        .CODE

;************************************************************************************

_main   PROC

;----------------------------------

;DS = DGROUP

        mov     ax,@data
        mov     ds,ax

;----------------------------------

;display the string

        mov     dx,offset s$Hello
        mov     ah,9
        int     21h

;----------------------------------

;wait for key press

WaitKy: mov     ah,1
        int     16h
        jz      WaitKy

        mov     ah,0
        int     16h

;----------------------------------

;terminate

        mov     ax,4C00h
        int     21h

_main   ENDP

;####################################################################################

        END     _main

nidud

  • Member
  • *****
  • Posts: 2388
    • https://github.com/nidud/asmc
Re: How to move the mouse cursor with the keyboard
« Reply #4 on: January 11, 2013, 10:59:40 AM »
deleted
« Last Edit: February 25, 2022, 06:10:39 AM by nidud »

sinsi

  • Guest
Re: How to move the mouse cursor with the keyboard
« Reply #5 on: January 11, 2013, 01:11:52 PM »
Code: [Select]
mov al,4
mov bh,0
int 10h

Int 10h needs the function in AH but you don't set it to anything.

dedndave

  • Member
  • *****
  • Posts: 8828
  • Still using Abacus 2.0
    • DednDave
Re: How to move the mouse cursor with the keyboard
« Reply #6 on: January 11, 2013, 01:16:38 PM »
set video mode 4 ???
i don't remember what mode 4 is, but that doesn't sound right

dedndave

  • Member
  • *****
  • Posts: 8828
  • Still using Abacus 2.0
    • DednDave
Re: How to move the mouse cursor with the keyboard
« Reply #7 on: January 11, 2013, 01:26:05 PM »
that's what it is, though - lol
mov ax,4

MichaelW

  • Global Moderator
  • Member
  • *****
  • Posts: 1196
Re: How to move the mouse cursor with the keyboard
« Reply #8 on: January 11, 2013, 01:32:37 PM »
Mode 4 is a CGA emulation mode, 320x200, 4-color (2bpp), 1 page, starting address B8000h.
Well Microsoft, here’s another nice mess you’ve gotten us into.

dedndave

  • Member
  • *****
  • Posts: 8828
  • Still using Abacus 2.0
    • DednDave
Re: How to move the mouse cursor with the keyboard
« Reply #9 on: January 11, 2013, 01:41:19 PM »
on my machine, the cursor is the size of texas - lol

i used to use mode 13h a lot for graphics
i remember having to make my own cursor because it was too big   :P
but, i don't think it was as big as this one

dedndave

  • Member
  • *****
  • Posts: 8828
  • Still using Abacus 2.0
    • DednDave
Re: How to move the mouse cursor with the keyboard
« Reply #10 on: January 11, 2013, 01:59:45 PM »
here is a cursor i used to use for mode 13h (320x200 256 colors)
i used words instead of bytes - the high byte was used as the z-buffer   :P
but, you can use this as a template to make whatever you like

the 0 words are transparent
Code: [Select]
; F6 = black
; FE = white
;
CBMEXI  DW      0F6h,0,0,0,0,0,0
        DW      0F6h,0F6h,0,0,0,0,0
        DW      0F6h,0FEh,0F6h,0,0,0,0
        DW      0F6h,0FEh,0FEh,0F6h,0,0,0
        DW      0F6h,0FEh,0FEh,0FEh,0F6h,0,0
        DW      0F6h,0FEh,0FEh,0FEh,0FEh,0F6h,0
        DW      0F6h,0FEh,0FEh,0FEh,0FEh,0FEh,0F6h
        DW      0F6h,0FEh,0FEh,0FEh,0FEh,0F6h,0
        DW      0F6h,0F6h,0F6h,0FEh,0FEh,0F6h,0
        DW      0,0,0,0F6h,0FEh,0FEh,0F6h
        DW      0,0,0,0F6h,0F6h,0F6h,0

majid1605

  • Guest
Re: How to move the mouse cursor with the keyboard
« Reply #11 on: January 11, 2013, 08:30:48 PM »
Thanks, everyone :eusa_clap:
I changed the code as follows.
There is a problem with move up.its work any key .  :icon_eek:

Code: [Select]
.model small
.stack
.code
start:
;   mov ax, datasg
;   mov ds, ax
    ;------------ ur programm


mov al,4
mov bh,0
int 10h

mov bh,0
mov bl,1001b
mov ah,0Bh
int 10h

mov ax,0
int 33h

mov ax,01h
int 33h

;mov dx,101h
;mov cx,161h
lable1:

mov ah,10h
int 16h
cmp ah,48h ;upArrow key 
je lable
cmp ah,50h ;DownArrow key
je lable2
cmp ah,4Dh ;RightArrow key 
je lable3
cmp ah,4Bh ;LeftArrow key 
je lable4


lable:; Moved up
mov ax,03h
int 33h
dec dx
mov ax,04h
int 33h
cmp dx,0
jne lable1

lable2:; Moved Down
mov ax,03h
int 33h
inc dx
mov ax,04h
int 33h
cmp dx,199h
jne lable1

lable3:; Moved right
mov ax,03h
int 33h
inc cx
mov ax,04h
int 33h
cmp dx,199h
jne lable1

lable4:; Moved left
mov ax,03h
int 33h
dec cx
mov ax,04h
int 33h
cmp dx,199h
jne lable1

    ;------------ end of program
    mov ax, 4c00h
    int 21h

     end start

dedndave

  • Member
  • *****
  • Posts: 8828
  • Still using Abacus 2.0
    • DednDave
Re: How to move the mouse cursor with the keyboard
« Reply #12 on: January 11, 2013, 08:38:20 PM »
that's because of the logic in this part
Code: [Select]
int 16h
cmp ah,48h ;upArrow key 
je lable
cmp ah,50h ;DownArrow key
je lable2
cmp ah,4Dh ;RightArrow key 
je lable3
cmp ah,4Bh ;LeftArrow key 
je lable4

lable:; Moved up

notice that, if none of the conditions are met, the "Moved up" code is executed

dedndave

  • Member
  • *****
  • Posts: 8828
  • Still using Abacus 2.0
    • DednDave
Re: How to move the mouse cursor with the keyboard
« Reply #13 on: January 11, 2013, 08:43:53 PM »
you can fix it like this
Code: [Select]
int 16h
cmp ah,50h ;DownArrow key
je lable2
cmp ah,4Dh ;RightArrow key 
je lable3
cmp ah,4Bh ;LeftArrow key 
je lable4
cmp ah,48h ;upArrow key 
jne test_something_else

lable:; Moved up

the last test is for the upArrow key
if it's not upArrow - do something else
the "something else" can be test the mouse or go back and wait for another key

majid1605

  • Guest
Re: How to move the mouse cursor with the keyboard
« Reply #14 on: January 11, 2013, 09:35:02 PM »
Thank you my friend

Why is the cursor out screen left and bottom.unless the screen is 320 x 200