News:

;) This forum is the property of Proton software developers

Main Menu

Draw straght line.

Started by towlerg, Apr 08, 2022, 11:59 AM

Previous topic - Next topic

towlerg

I've been looking for a utility the will force mouse moves to either horizontal and vertical. Shouldn't be too tough, each time you get a mouse move you reset either x or y to it's start value. A nice addon to that would be to draw a straight line at an arbitrary angle. Anybody know of such a beast?


shantanu@india

In drawing softwares like AutoCAD just press F8 for orthogonal mouse movement.
Are you talking about the entire screen of Windows?
Regards
Shantanu

towlerg

I was hoping to find a utiliy for use with several applications.

keytapper

In Linux there's the way to move the mouse by the keyboard input. Maybe some good fellow has ported this feature on Windows.
Ignorance comes with a cost

towlerg

Actually I think it already exists in Win but rely's on keyboard number pad and it's kindda clunky anyway.

Parmin

Mouse data packets have distinct location feedback for each axis of movement.
By parsing the packet and changing the singular axis data to 0 between the mouse and the computer, you can lock the input of a particular axis and in essence force it to draw a straight line either in the horizontal or vertical direction.

Below is the "older" style mouse data packet.
they came in 3 bytes of data

        D7      D6      D5      D4      D3      D2      D1      D0
 
1.      X       1       LB      RB      Y7      Y6      X7      X6
2.      X       0       X5      X4      X3      X2      X1      X0     
3.      X       0       Y5      Y4      Y3      Y2      Y1      Y0

LB is the state of the left button (1 means pressed down)
RB is the state of the right button (1 means pressed down)
X7-X0 movement in X direction since last packet (signed byte)
Y7-Y0 movement in Y direction since last packet (signed byte)
     

towlerg

Thanks Parmin, I think I know how to do it (apart from the line between to points) I was kindda hoping someone had already done it.

xldaedalus

A couple of questions for clarification

BYTE 1 is signed or unsigned?  or does it matter?

First tx of 3 bytes, what is the position of the Mouse "Cursor", in otherwords, how would you know where the cursor is if all mouse is doing is sending how it moved from last position? Or is first cursor position always 0, 0?

Is there a specific baud and data rate required, ie time between packets?

Does sending this data on an open com port cause a Windows computer to recognize device as an HID device?


Reason I'm asking, I want to write a library that mimics the actions of a mouse to "automatically" play a game based on external input of different types

Thanks
 
Never, never, never give up

Stephen Moss

@xldaedalus
As you mention HID device I presume you are looking at a USB mouse here, in which case most of your answers can be found in USB 2.0 specifications documentation at usb.org.

I may be wrong but if memory serves...
  • The data @Parmin gave would incorrect as I believe for a USB mouse it is 1 byte each for X, Y and Z (Scrollwheel) and one byte for buttons, or 1 byte for X and Y (Scrollwheel) and one byte for buttons if configured as a two old style 2 button mouse.
  • All data bytes except for the buttons are signed, otherwise how would you know which direction you are moving.

Quote from: xldaedalus on Apr 07, 2025, 07:51 PMDoes sending this data on an open com port cause a Windows computer to recognize device as an HID device?
If you are talking about connecting a serial device to a USB port then not unless you are using a USB to serial cable to connect them whereby the cable identifies itself as a serial HID device. Connecting a USB device to an old style serial COM port would not work.

If memory serves when a USB device is connected to the USB bus its resistors pull down the D+ and or D- lines, this indicates to the host device that a new device has been connected and which Data lines were pulled down tells the host whether or not it is a Low, High or Full speed device. Now you could infer from it being a low speed device that it is a HID device, but usually the USB protocol then enumerates the device...
  • Resets the USB bus
  • Addresses the device
  • Resets the USB bus
  • Then requests its configuration, which tells the host things like type of device it is, which communication protocols to use and what data it provides, some devices like mice can have multiple configurations that can be software selected (i.e. operate as an old style 2 button or newer 3 button type).
  • Tells the device which configuration it wants it to use (if more than one).
  • Reset the USB Bus again, then the device can be used.

Thus for a PC to recognise a device a HID I believe the device would have to be a USB slave that identifies itself as a HID device

Quote from: xldaedalus on Apr 07, 2025, 07:51 PMReason I'm asking, I want to write a library that mimics the actions of a mouse to "automatically" play a game based on external input of different types
I do not know what software you want to do this with, but if it is software you are writing yourself then whatever program you are using to do so must have a pointer or cursor command of some kind, so you should be able to read the data from your desired controller then it should be something like...
X_Cursor_Position += Scaled Controller_X_input
Y_Cursor_Position += scaled Controller_Y_input
LMouse_Button Down = Controller_Button_X
RMouse_Button_Down = Controller_Button_Y

Pepe

#9
demo proteus
Device = 18F2550
Declare Xtal = 48
Declare Bootloader Off
Declare Onboard_USB On
Declare Create_Coff On
Declare Optimiser_Level = 3
Declare HRSOut_Pin = PORTC.6

Declare Hserial_Baud = 9600

Include "mouse_desc.inc"

Declare Adin_Res = 10
Declare Adin_Tad = FRC
Declare Adin_Stime = 50
ADCON2bits_ADFM = 1
ADCON1 = $0D  ' Todos analalogicos como digitales excepto AN0 y AN1

Symbol GIE = INTCON.7
Symbol TMR0IE = INTCON.5
Symbol TMR0IF = INTCON.2

Dim fLeer As Bit
Dim act As Bit
Dim fTx As Bit
Dim BUFFER[4] As Byte

Dim CANALx As Word
Dim CANALy As Word
Dim CAx As Word
Dim CAy As Word
Dim Botones As Byte
Dim Boton As Byte
Dim movX As SByte
Dim movY As SByte

On_Hardware_Interrupt GoTo Isr

Clear

TRISA = %11111111 ' Todo entradas
TRISB = %11111111 ' Entradas para botones
TRISC = %10111111

TMR0L = 21
T0CON = $C7  ' Timer0 ON, prescaler 256

DelayMS 500

TMR0IE = 1
GIE = 1

Repeat
    USBPoll
Until USB_tConnected = 1 Or USB_tConfigured = 1

Do
    If fLeer = 1 Then
   
        fLeer = 0
        act = 0
        CANALx = ADIn 1  ' Eje X
        If CAx <> CANALx Then
                              CAx = CANALx
                              act = 1
        EndIf   
        CANALy = ADIn 0  ' Eje Y
        If CAy <> CANALy Then
                              CAy = CANALy
                              act = 1
        EndIf
           
        ' Leer botones
        Botones = 0
        If PORTB.0 = 0 Then Set Botones.0 ' Click izquierdo
        If PORTB.1 = 0 Then Set Botones.1 ' Click derecho
        If PORTB.2 = 0 Then Set Botones.2 ' Click medio
       
        If Boton <> Botones Then
                                Boton=Botones
                                act = 1
        EndIf
       
        If act = 1 Then
                       
          ' Mapear de 0-1023 a -127 a 127
       
          movX = (CANALx - 511) / 4
          movY = (CANALy - 511) / 4
       
          BUFFER[0] = Botones
          BUFFER[1] = movX
          BUFFER[2] = movY
          BUFFER[3] = 0 ' Scroll (puede usarse otro canal)
       
          HRSOutLn "X " , SDec movX , "  Y " , SDec movY , "  L " , Dec Botones.0 , "  R " , Dec Botones.1 , "  M " , Dec Botones.2                       
       
        EndIf
       
        fTx = 1
   
    End If

    If fTx = 1 Then
        DoUSBOut:
        USBOut 1, BUFFER, 4, DoUSBOut
        fTx = 0
    End If
Loop

Isr:
Context Save
    If TMR0IF = 1 Then
        TMR0L = 21            '5ms pool
        fLeer = 1
        TMR0IF = 0
    End If
Context Restore

;-------------------------------------------------------------------------------
;**** Added by Fuse Configurator ****
; Use the Fuse Configurator plug-in to change these settings

Config_Start
  PLLDIV = 5    ;Divide by 5 (20 MHz oscillator input)
  CPUDIV = OSC1_PLL2    ;[Primary Oscillator Src: /1][96 MHz PLL Src: /2]
  USBDIV = 2    ;USB clock source comes from the 96 MHz PLL divided by 2
  FOSC = HSPLL_HS    ;HS oscillator, PLL enabled (HSPLL)
  FCMEN = OFF    ;Fail-Safe Clock Monitor disabled
  IESO = OFF    ;Oscillator Switchover mode disabled
  PWRT = On        ;PWRT enabled
  BOR = OFF      ;Brown-out Reset disabled in hardware and software
  BORV = 3        ;Minimum setting 2.05V
  VREGEN = On    ;USB voltage regulator enabled
  WDT = OFF      ;WDT enabled (control is placed on the SWDTEN bit)
  WDTPS = 256      ;1:32768
  CCP2MX = On    ;CCP2 input/output is not multiplexed with RB3
  PBADEN = OFF    ;PORTB<4:0> pins are configured as digital I/O on Reset
  LPT1OSC = OFF ;Timer1 configured for higher power operation
  MCLRE = OFF    ;MCLR pin enabled; RE3 input pin disabled
  STVREN = OFF    ;Stack full/underflow will not cause Reset
  LVP = OFF        ;Single-Supply ICSP disabled
  XINST = OFF    ;Instruction set extension and Indexed Addressing mode disabled (Legacy mode)
  Debug = OFF    ;Background debugger disabled, RB6 and RB7 configured as general purpose I/O pins
  Cp0 = On    ;Block 0 (000800-001FFFh) is not code-protected
  CP1 = On    ;Block 1 (002000-003FFFh) is not code-protected
  CP2 = On    ;Block 2 (004000-005FFFh) is not code-protected
  CP3 = On    ;Block 3 (006000-007FFFh) is not code-protected
  CPB = On    ;Boot block (000000-0007FFh) is not code-protected
  CPD = OFF    ;Data EEPROM is not code-protected
  WRT0 = On    ;Block 0 (000800-001FFFh) is not write-protected
  WRT1 = On    ;Block 1 (002000-003FFFh) is not write-protected
  WRT2 = On    ;Block 2 (004000-005FFFh) is not write-protected
  WRT3 = On    ;Block 3 (006000-007FFFh) is not write-protected
  WRTC = On    ;Configuration registers (300000-3000FFh) are not write-protected
  WRTB = On    ;Boot block (000000-0007FFh) is not write-protected
  WRTD = OFF    ;Data EEPROM is not write-protected
  EBTR0 = OFF    ;Block 0 (000800-001FFFh) is not protected from table reads executed in other blocks
  EBTR1 = OFF    ;Block 1 (002000-003FFFh) is not protected from table reads executed in other blocks
  EBTR2 = OFF    ;Block 2 (004000-005FFFh) is not protected from table reads executed in other blocks
  EBTR3 = OFF    ;Block 3 (006000-007FFFh) is not protected from table reads executed in other blocks
  EBTRB = OFF    ;Boot block (000000-0007FFh) is not protected from table reads executed in other blocks
Config_End

;**** End of Fuse Configurator Settings ****
;-------------------------------------------------------------------------------