using MouseX() and MouseY() - help please

Just starting out? Need help? Post your questions and find answers here.
SFSxOI
Addict
Addict
Posts: 2970
Joined: Sat Dec 31, 2005 5:24 pm
Location: Where ya would never look.....

using MouseX() and MouseY() - help please

Post by SFSxOI »

is there any way to use the MouseX and MouseY commands without opening a screen or windowed screen?

I understand that the MouseX and MouseY commands will return the absolute coords of the mouse. This is what I need - I need the screen coordinates of another directX window converted to absolute mouse coords. And I need to also be able to convert the mouse relative coordinats to absolute coordinates.

for the first part I thought it would be great if MouseX and MouseY could do this by just returning the absolute coordinates.
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8452
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Post by netmaestro »

is there any way to use the MouseX and MouseY commands without opening a screen or windowed screen?
If you don't open a screen there are some options, WindowMouseX() and WindowMouseY(), DeskTopMouseX() and DeskTopMouseY(), or if you like dipping into the Windows API, there is GetCursorPos_(). Lots of choices, really.
Last edited by netmaestro on Sat Feb 25, 2006 6:01 pm, edited 1 time in total.
BERESHEIT
josku_x
Addict
Addict
Posts: 997
Joined: Sat Sep 24, 2005 2:08 pm

Post by josku_x »

If it's for Windows, you could do this:

Code: Select all

GetCursorPos_(Cursor.POINT)

Debug Cursor\x
Debug Cursor\y
EDIT: @netmaestro: grrr!
SFSxOI
Addict
Addict
Posts: 2970
Joined: Sat Dec 31, 2005 5:24 pm
Location: Where ya would never look.....

Post by SFSxOI »

well, the cursor is out of the question because directX doesn't care about the cursor and leaves it up to your code to keep track of the mouse.

hers the code i'm working with:

Code: Select all

#DIRECTINPUT_VERSION = $0800 
#DI_OK = #S_OK 
#DISCL_EXCLUSIVE = $00000001 
#DISCL_NONEXCLUSIVE = $00000002 
#DISCL_FOREGROUND = $00000004 
#DISCL_BACKGROUND = $00000008
#MOUSE_SPEED = 2 

;{ DIK-Constants (DirectInput-Key) 
#DIK_ESCAPE          = $01 
#DIK_1               = $02 
#DIK_2               = $03 
#DIK_3               = $04 
#DIK_4               = $05 
#DIK_5               = $06 
#DIK_6               = $07 
#DIK_7               = $08 
#DIK_8               = $09 
#DIK_9               = $0A 
#DIK_0               = $0B 
#DIK_MINUS           = $0C    ; - on main keyboard 
#DIK_EQUALS          = $0D 
#DIK_BACK            = $0E    ; backspace 
#DIK_TAB             = $0F 
#DIK_Q               = $10 
#DIK_W               = $11 
#DIK_E               = $12 
#DIK_R               = $13 
#DIK_T               = $14 
#DIK_Y               = $15 
#DIK_U               = $16 
#DIK_I               = $17 
#DIK_O               = $18 
#DIK_P               = $19 
#DIK_LBRACKET        = $1A 
#DIK_RBRACKET        = $1B 
#DIK_RETURN          = $1C    ; Enter on main keyboard 
#DIK_LCONTROL        = $1D 
#DIK_A               = $1E 
#DIK_S               = $1F 
#DIK_D               = $20 
#DIK_F               = $21 
#DIK_G               = $22 
#DIK_H               = $23 
#DIK_J               = $24 
#DIK_K               = $25 
#DIK_L               = $26 
#DIK_SEMICOLON       = $27 
#DIK_APOSTROPHE      = $28 
#DIK_GRAVE           = $29    ; accent GRAVE 
#DIK_LSHIFT          = $2A 
#DIK_BACKSLASH       = $2B 
#DIK_Z               = $2C 
#DIK_X               = $2D 
#DIK_C               = $2E 
#DIK_V               = $2F 
#DIK_B               = $30 
#DIK_N               = $31 
#DIK_M               = $32 
#DIK_COMMA           = $33 
#DIK_PERIOD          = $34    ; . on main keyboard 
#DIK_SLASH           = $35    ; / on main keyboard 
#DIK_RSHIFT          = $36 
#DIK_MULTIPLY        = $37    ; * on numeric keypad 
#DIK_LMENU           = $38    ; left Alt 
#DIK_SPACE           = $39 
#DIK_CAPITAL         = $3A 
#DIK_F1              = $3B 
#DIK_F2              = $3C 
#DIK_F3              = $3D 
#DIK_F4              = $3E 
#DIK_F5              = $3F 
#DIK_F6              = $40 
#DIK_F7              = $41 
#DIK_F8              = $42 
#DIK_F9              = $43 
#DIK_F10             = $44 
#DIK_NUMLOCK         = $45 
#DIK_SCROLL          = $46    ; Scroll Lock 
#DIK_NUMPAD7         = $47 
#DIK_NUMPAD8         = $48 
#DIK_NUMPAD9         = $49 
#DIK_SUBTRACT        = $4A    ; - on numeric keypad 
#DIK_NUMPAD4         = $4B 
#DIK_NUMPAD5         = $4C 
#DIK_NUMPAD6         = $4D 
#DIK_ADD             = $4E    ; + on numeric keypad 
#DIK_NUMPAD1         = $4F 
#DIK_NUMPAD2         = $50 
#DIK_NUMPAD3         = $51 
#DIK_NUMPAD0         = $52 
#DIK_DECIMAL         = $53    ; . on numeric keypad 
#DIK_OEM_102         = $56    ; < > | on UK/Germany keyboards 
#DIK_F11             = $57 
#DIK_F12             = $58 
#DIK_F13             = $64    ;                     (NEC PC98) 
#DIK_F14             = $65    ;                     (NEC PC98) 
#DIK_F15             = $66    ;                     (NEC PC98) 
#DIK_KANA            = $70    ; (Japanese keyboard)            
#DIK_ABNT_C1         = $73    ; / ? on Portugese (Brazilian) keyboards 
#DIK_CONVERT         = $79    ; (Japanese keyboard)            
#DIK_NOCONVERT       = $7B    ; (Japanese keyboard)            
#DIK_YEN             = $7D    ; (Japanese keyboard)            
#DIK_ABNT_C2         = $7E    ; Numpad . on Portugese (Brazilian) keyboards 
#DIK_NUMPADEQUALS    = $8D    ; = on numeric keypad (NEC PC98) 
#DIK_PREVTRACK       = $90    ; Previous Track (DIK_CIRCUMFLEX on Japanese keyboard) 
#DIK_AT              = $91    ;                     (NEC PC98) 
#DIK_COLON           = $92    ;                     (NEC PC98) 
#DIK_UNDERLINE       = $93    ;                     (NEC PC98) 
#DIK_KANJI           = $94    ; (Japanese keyboard)            
#DIK_STOP            = $95    ;                     (NEC PC98) 
#DIK_AX              = $96    ;                     (Japan AX) 
#DIK_UNLABELED       = $97    ;                        (J3100) 
#DIK_NEXTTRACK       = $99    ; Next Track 
#DIK_NUMPADENTER     = $9C    ; Enter on numeric keypad 
#DIK_RCONTROL        = $9D 
#DIK_MUTE            = $A0    ; Mute 
#DIK_CALCULATOR      = $A1    ; Calculator 
#DIK_PLAYPAUSE       = $A2    ; Play / Pause 
#DIK_MEDIASTOP       = $A4    ; Media Stop 
#DIK_VOLUMEDOWN      = $AE    ; Volume - 
#DIK_VOLUMEUP        = $B0    ; Volume + 
#DIK_WEBHOME         = $B2    ; Web home 
#DIK_NUMPADCOMMA     = $B3    ; , on numeric keypad (NEC PC98) 
#DIK_DIVIDE          = $B5    ; / on numeric keypad 
#DIK_SYSRQ           = $B7 
#DIK_RMENU           = $B8    ; right Alt 
#DIK_PAUSE           = $C5    ; Pause 
#DIK_HOME            = $C7    ; home on arrow keypad 
#DIK_UP              = $C8    ; UpArrow on arrow keypad 
#DIK_PRIOR           = $C9    ; PgUp on arrow keypad 
#DIK_LEFT            = $CB    ; LeftArrow on arrow keypad 
#DIK_RIGHT           = $CD    ; RightArrow on arrow keypad 
#DIK_END             = $CF    ; End on arrow keypad 
#DIK_DOWN            = $D0    ; DownArrow on arrow keypad 
#DIK_NEXT            = $D1    ; PgDn on arrow keypad 
#DIK_INSERT          = $D2    ; Insert on arrow keypad 
#DIK_DELETE          = $D3    ; Delete on arrow keypad 
#DIK_LWIN            = $DB    ; left windows key 
#DIK_RWIN            = $DC    ; right windows key 
#DIK_APPS            = $DD    ; AppMenu key 
#DIK_POWER           = $DE    ; System Power 
#DIK_SLEEP           = $DF    ; System Sleep 
#DIK_WAKE            = $E3    ; System Wake 
#DIK_WEBSEARCH       = $E5    ; Web Search 
#DIK_WEBFAVORITES    = $E6    ; Web Favorites 
#DIK_WEBREFRESH      = $E7    ; Web Refresh 
#DIK_WEBSTOP         = $E8    ; Web Stop 
#DIK_WEBFORWARD      = $E9    ; Web Forward 
#DIK_WEBBACK         = $EA    ; Web Back 
#DIK_MYCOMPUTER      = $EB    ; My Computer 
#DIK_MAIL            = $EC    ; Mail 
#DIK_MEDIASELECT     = $ED    ; Media Select 
      
; Alternate names For keys, To facilitate transition from DOS. 
        
#DIK_BACKSPACE      = #DIK_BACK            ; backspace 
#DIK_NUMPADSTAR     = #DIK_MULTIPLY        ; * on numeric keypad 
#DIK_LALT           = #DIK_LMENU           ; left Alt 
#DIK_CAPSLOCK       = #DIK_CAPITAL         ; CapsLock 
#DIK_NUMPADMINUS    = #DIK_SUBTRACT        ; - on numeric keypad 
#DIK_NUMPADPLUS     = #DIK_ADD             ; + on numeric keypad 
#DIK_NUMPADPERIOD   = #DIK_DECIMAL         ; . on numeric keypad 
#DIK_NUMPADSLASH    = #DIK_DIVIDE          ; / on numeric keypad 
#DIK_RALT           = #DIK_RMENU           ; right Alt 
#DIK_UPARROW        = #DIK_UP              ; UpArrow on arrow keypad 
#DIK_PGUP           = #DIK_PRIOR           ; PgUp on arrow keypad 
#DIK_LEFTARROW      = #DIK_LEFT            ; LeftArrow on arrow keypad 
#DIK_RIGHTARROW     = #DIK_RIGHT           ; RightArrow on arrow keypad 
#DIK_DOWNARROW      = #DIK_DOWN            ; DownArrow on arrow keypad 
#DIK_PGDN           = #DIK_NEXT            ; PgDn on arrow keypad 
        
; Alternate names For keys originally not used on US keyboards. 
          
#DIK_CIRCUMFLEX     = #DIK_PREVTRACK       ; Japanese keyboard 
;} 

;{ DIDFT-Constants 
#DIDFT_ALL = $00000000 
#DIDFT_RELAXIS = $00000001 
#DIDFT_ABSAXIS = $00000002 
#DIDFT_AXIS = $00000003 
#DIDFT_PSHBUTTON = $00000004 
#DIDFT_TGLBUTTON = $00000008 
#DIDFT_BUTTON = $0000000C 
#DIDFT_POV = $00000010 
#DIDFT_COLLECTION = $00000040 
#DIDFT_NODATA = $00000080 
#DIDFT_ANYINSTANCE = $00FFFF00 
#DIDFT_INSTANCEMASK = #DIDFT_ANYINSTANCE 
;#DIDFT_MAKEINSTANCE(n) = ((WORD)(n) << 8) 
;#DIDFT_GETTYPE(n) = LOBYTE(n) 
;#DIDFT_GETINSTANCE(n) = LOWORD((n) >> 8) 
#DIDFT_FFACTUATOR = $01000000 
#DIDFT_FFEFFECTTRIGGER = $02000000 
#DIDFT_OUTPUT = $10000000 
;#DIDFT_ENUMCOLLECTION(n) = ((WORD)(n) << 8) 
#DIDFT_NOCOLLECTION = $00FFFF00 
#DIDFT_OPTIONAL = $80000000 ;} 

#DIDF_ABSAXIS = $00000001 
#DIDF_RELAXIS = $00000002 

#DIGDD_PEEK = $00000001

Global wnx.l, wny.l
Global hwnd.l
;Global w$
Global mintMouseX.l
Global mintMouseY.l
Global wdth.l 
Global hght.l


Procedure DEFINE_GUID(*p.GUID, Data1.l, Data2.w, Data3.w, Data4_1.b, Data4_2.b, Data4_3.b, Data4_4.b, Data4_5.b, Data4_6.b, Data4_7.b, Data4_8.b) 
  *p\Data1 = Data1 
  *p\Data2 = Data2 
  *p\Data3 = Data3 
  *p\Data4[0] = Data4_1 
  *p\Data4[1] = Data4_2 
  *p\Data4[2] = Data4_3 
  *p\Data4[3] = Data4_4 
  *p\Data4[4] = Data4_5 
  *p\Data4[5] = Data4_6 
  *p\Data4[6] = Data4_7 
  *p\Data4[7] = Data4_8 
EndProcedure 

DefType.GUID ;{ 
DEFINE_GUID(CLSID_DirectInput,$25E609E0,$B259,$11CF,$BF,$C7,$44,$45,$53,$54,$00,$00); 
DEFINE_GUID(CLSID_DirectInputDevice,$25E609E1,$B259,$11CF,$BF,$C7,$44,$45,$53,$54,$00,$00); 

DEFINE_GUID(CLSID_DirectInput8,$25E609E4,$B259,$11CF,$BF,$C7,$44,$45,$53,$54,$00,$00); 
DEFINE_GUID(CLSID_DirectInputDevice8,$25E609E5,$B259,$11CF,$BF,$C7,$44,$45,$53,$54,$00,$00); 

; Interfaces 
DEFINE_GUID(IID_IDirectInputA,$89521360,$AA8A,$11CF,$BF,$C7,$44,$45,$53,$54,$00,$00); 
DEFINE_GUID(IID_IDirectInputW,$89521361,$AA8A,$11CF,$BF,$C7,$44,$45,$53,$54,$00,$00); 
DEFINE_GUID(IID_IDirectInput2A,$5944E662,$AA8A,$11CF,$BF,$C7,$44,$45,$53,$54,$00,$00); 
DEFINE_GUID(IID_IDirectInput2W,$5944E663,$AA8A,$11CF,$BF,$C7,$44,$45,$53,$54,$00,$00); 
DEFINE_GUID(IID_IDirectInput7A,$9A4CB684,$236D,$11D3,$8E,$9D,$00,$C0,$4F,$68,$44,$AE); 
DEFINE_GUID(IID_IDirectInput7W,$9A4CB685,$236D,$11D3,$8E,$9D,$00,$C0,$4F,$68,$44,$AE); 
DEFINE_GUID(IID_IDirectInput8A,$BF798030,$483A,$4DA2,$AA,$99,$5D,$64,$ED,$36,$97,$00); 
DEFINE_GUID(IID_IDirectInput8W,$BF798031,$483A,$4DA2,$AA,$99,$5D,$64,$ED,$36,$97,$00); 
DEFINE_GUID(IID_IDirectInputDeviceA,$5944E680,$C92E,$11CF,$BF,$C7,$44,$45,$53,$54,$00,$00); 
DEFINE_GUID(IID_IDirectInputDeviceW,$5944E681,$C92E,$11CF,$BF,$C7,$44,$45,$53,$54,$00,$00); 
DEFINE_GUID(IID_IDirectInputDevice2A,$5944E682,$C92E,$11CF,$BF,$C7,$44,$45,$53,$54,$00,$00); 
DEFINE_GUID(IID_IDirectInputDevice2W,$5944E683,$C92E,$11CF,$BF,$C7,$44,$45,$53,$54,$00,$00); 
DEFINE_GUID(IID_IDirectInputDevice7A,$57D7C6BC,$2356,$11D3,$8E,$9D,$00,$C0,$4F,$68,$44,$AE); 
DEFINE_GUID(IID_IDirectInputDevice7W,$57D7C6BD,$2356,$11D3,$8E,$9D,$00,$C0,$4F,$68,$44,$AE); 
DEFINE_GUID(IID_IDirectInputDevice8A,$54D41080,$DC15,$4833,$A4,$1B,$74,$8F,$73,$A3,$81,$79); 
DEFINE_GUID(IID_IDirectInputDevice8W,$54D41081,$DC15,$4833,$A4,$1B,$74,$8F,$73,$A3,$81,$79); 
DEFINE_GUID(IID_IDirectInputEffect,$E7E1F7C0,$88D2,$11D0,$9A,$D0,$00,$A0,$C9,$A0,$6E,$35); 

; Predefined object types 
DEFINE_GUID(GUID_XAxis,$A36D02E0,$C9F3,$11CF,$BF,$C7,$44,$45,$53,$54,$00,$00); 
DEFINE_GUID(GUID_YAxis,$A36D02E1,$C9F3,$11CF,$BF,$C7,$44,$45,$53,$54,$00,$00); 
DEFINE_GUID(GUID_ZAxis,$A36D02E2,$C9F3,$11CF,$BF,$C7,$44,$45,$53,$54,$00,$00); 
DEFINE_GUID(GUID_RxAxis,$A36D02F4,$C9F3,$11CF,$BF,$C7,$44,$45,$53,$54,$00,$00); 
DEFINE_GUID(GUID_RyAxis,$A36D02F5,$C9F3,$11CF,$BF,$C7,$44,$45,$53,$54,$00,$00); 
DEFINE_GUID(GUID_RzAxis,$A36D02E3,$C9F3,$11CF,$BF,$C7,$44,$45,$53,$54,$00,$00); 
DEFINE_GUID(GUID_Slider,$A36D02E4,$C9F3,$11CF,$BF,$C7,$44,$45,$53,$54,$00,$00); 
DEFINE_GUID(GUID_Button,$A36D02F0,$C9F3,$11CF,$BF,$C7,$44,$45,$53,$54,$00,$00); 
DEFINE_GUID(GUID_Key,$55728220,$D33C,$11CF,$BF,$C7,$44,$45,$53,$54,$00,$00); 
DEFINE_GUID(GUID_POV,$A36D02F2,$C9F3,$11CF,$BF,$C7,$44,$45,$53,$54,$00,$00); 
DEFINE_GUID(GUID_Unknown,$A36D02F3,$C9F3,$11CF,$BF,$C7,$44,$45,$53,$54,$00,$00); 

; Predefined product GUIDs 
DEFINE_GUID(GUID_SysMouse,$6F1D2B60,$D5A0,$11CF,$BF,$C7,$44,$45,$53,$54,$00,$00); 
DEFINE_GUID(GUID_SysKeyboard,$6F1D2B61,$D5A0,$11CF,$BF,$C7,$44,$45,$53,$54,$00,$00); 
DEFINE_GUID(GUID_Joystick,$6F1D2B70,$D5A0,$11CF,$BF,$C7,$44,$45,$53,$54,$00,$00); 

; Predefined forcefeedback effects 
DEFINE_GUID(GUID_ConstantForce,$13541C20,$8E33,$11D0,$9A,$D0,$00,$A0,$C9,$A0,$6E,$35); 
DEFINE_GUID(GUID_RampForce,$13541C21,$8E33,$11D0,$9A,$D0,$00,$A0,$C9,$A0,$6E,$35); 
DEFINE_GUID(GUID_Square,$13541C22,$8E33,$11D0,$9A,$D0,$00,$A0,$C9,$A0,$6E,$35); 
DEFINE_GUID(GUID_Sine,$13541C23,$8E33,$11D0,$9A,$D0,$00,$A0,$C9,$A0,$6E,$35); 
DEFINE_GUID(GUID_Triangle,$13541C24,$8E33,$11D0,$9A,$D0,$00,$A0,$C9,$A0,$6E,$35); 
DEFINE_GUID(GUID_SawtoothUp,$13541C25,$8E33,$11D0,$9A,$D0,$00,$A0,$C9,$A0,$6E,$35); 
DEFINE_GUID(GUID_SawtoothDown,$13541C26,$8E33,$11D0,$9A,$D0,$00,$A0,$C9,$A0,$6E,$35); 
DEFINE_GUID(GUID_Spring,$13541C27,$8E33,$11D0,$9A,$D0,$00,$A0,$C9,$A0,$6E,$35); 
DEFINE_GUID(GUID_Damper,$13541C28,$8E33,$11D0,$9A,$D0,$00,$A0,$C9,$A0,$6E,$35); 
DEFINE_GUID(GUID_Inertia,$13541C29,$8E33,$11D0,$9A,$D0,$00,$A0,$C9,$A0,$6E,$35); 
DEFINE_GUID(GUID_Friction,$13541C2A,$8E33,$11D0,$9A,$D0,$00,$A0,$C9,$A0,$6E,$35); 
DEFINE_GUID(GUID_CustomForce,$13541C2B,$8E33,$11D0,$9A,$D0,$00,$A0,$C9,$A0,$6E,$35); 
DefType.l ;} 

Structure DIOBJECTDATAFORMAT 
  *pguid.GUID 
  dwOfs.l 
  dwType.l 
  dwFlags.l 
EndStructure 

Structure DIDATAFORMAT 
  dwSize.l 
  dwObjSize.l 
  dwFlags.l 
  dwDataSize.l 
  dwNumObjs.l 
  *rgodf.DIOBJECTDATAFORMAT 
EndStructure

;Keyboard 

Dim KBD_fmt.DIOBJECTDATAFORMAT(255) ;{ 

dwType = $8000000C 
For i = 0 To 255 
  KBD_fmt(i)\pguid = GUID_Key 
  KBD_fmt(i)\dwOfs = i 
  KBD_fmt(i)\dwType = dwType 
  KBD_fmt(i)\dwFlags = $00000000 
  dwType + $100 
Next ;} 

c_dfDIKeyboard.DIDATAFORMAT ;{ 

c_dfDIKeyboard\dwSize = SizeOf(DIDATAFORMAT) 
c_dfDIKeyboard\dwObjSize = SizeOf(DIOBJECTDATAFORMAT) 
c_dfDIKeyboard\dwFlags = $00000002 
c_dfDIKeyboard\dwDataSize = 256 
c_dfDIKeyboard\dwNumObjs = 256 
c_dfDIKeyboard\rgodf = @KBD_fmt() ;} 

;Mouse 

Structure DIMOUSESTATE 
  lx.l 
  ly.l 
  lZ.l 
  rgbButtons.b[4] 
EndStructure 

Structure DIMOUSESTATE2 
  lx.l 
  ly.l 
  lZ.l 
  rgbButtons.b[8] 
EndStructure

; DINSTATEMOUSE lx.l, ly.l, lZ.l returns distance moved since last call in device units not pixels
; to get distance in pixels use GetCursorPos

;{ DIMOFS-Constants 
#DIMOFS_X        = OffsetOf(DIMOUSESTATE2\lx) 
#DIMOFS_Y        = OffsetOf(DIMOUSESTATE2\ly) 
#DIMOFS_Z        = OffsetOf(DIMOUSESTATE2\lZ) 
#DIMOFS_BUTTON0  = OffsetOf(DIMOUSESTATE2\rgbButtons)+0 
#DIMOFS_BUTTON1  = OffsetOf(DIMOUSESTATE2\rgbButtons)+1 
#DIMOFS_BUTTON2  = OffsetOf(DIMOUSESTATE2\rgbButtons)+2 
#DIMOFS_BUTTON3  = OffsetOf(DIMOUSESTATE2\rgbButtons)+3 
#DIMOFS_BUTTON4  = OffsetOf(DIMOUSESTATE2\rgbButtons)+4 
#DIMOFS_BUTTON5  = OffsetOf(DIMOUSESTATE2\rgbButtons)+5 
#DIMOFS_BUTTON6  = OffsetOf(DIMOUSESTATE2\rgbButtons)+6 
#DIMOFS_BUTTON7  = OffsetOf(DIMOUSESTATE2\rgbButtons)+7 ;} 

Dim PTR_fmt.DIOBJECTDATAFORMAT(6) ;{ 

PTR_fmt(0)\pguid = GUID_XAxis :PTR_fmt(0)\dwOfs = 0 :PTR_fmt(0)\dwType = $00FFFF03 :PTR_fmt(0)\dwFlags = $00000000 
PTR_fmt(1)\pguid = GUID_YAxis :PTR_fmt(1)\dwOfs = 4 :PTR_fmt(1)\dwType = $00FFFF03 :PTR_fmt(1)\dwFlags = $00000000 
PTR_fmt(2)\pguid = GUID_ZAxis :PTR_fmt(2)\dwOfs = 8 :PTR_fmt(2)\dwType = $80FFFF03 :PTR_fmt(2)\dwFlags = $00000000 
PTR_fmt(3)\pguid = #Null :PTR_fmt(3)\dwOfs = 12 :PTR_fmt(3)\dwType = $00FFFF03 :PTR_fmt(3)\dwFlags = $00000000 
PTR_fmt(4)\pguid = #Null :PTR_fmt(4)\dwOfs = 13 :PTR_fmt(4)\dwType = $00FFFF03 :PTR_fmt(4)\dwFlags = $00000000 
PTR_fmt(5)\pguid = #Null :PTR_fmt(5)\dwOfs = 14 :PTR_fmt(5)\dwType = $80FFFF03 :PTR_fmt(5)\dwFlags = $00000000 
PTR_fmt(6)\pguid = #Null :PTR_fmt(6)\dwOfs = 15 :PTR_fmt(6)\dwType = $80FFFF03 :PTR_fmt(6)\dwFlags = $00000000 ;} 

c_dfDIMouse.DIDATAFORMAT ;{ 

c_dfDIMouse\dwSize = SizeOf(DIDATAFORMAT) 
c_dfDIMouse\dwObjSize = SizeOf(DIOBJECTDATAFORMAT) 
c_dfDIMouse\dwFlags = $00000002 
c_dfDIMouse\dwDataSize = 16 
c_dfDIMouse\dwNumObjs = 7 
c_dfDIMouse\rgodf = @PTR_fmt() ;} 

Dim dfDIMouse2.DIOBJECTDATAFORMAT(10) ;{ 
dfDIMouse2(0)\pguid = GUID_XAxis :dfDIMouse2(0)\dwOfs = #DIMOFS_X :dfDIMouse2(0)\dwType = #DIDFT_ANYINSTANCE | #DIDFT_AXIS :dfDIMouse2(0)\dwFlags = 0 
dfDIMouse2(1)\pguid = GUID_YAxis :dfDIMouse2(1)\dwOfs = #DIMOFS_Y :dfDIMouse2(1)\dwType = #DIDFT_ANYINSTANCE | #DIDFT_AXIS :dfDIMouse2(1)\dwFlags = 0 
dfDIMouse2(2)\pguid = GUID_ZAxis :dfDIMouse2(2)\dwOfs = #DIMOFS_Z :dfDIMouse2(2)\dwType = #DIDFT_OPTIONAL | #DIDFT_ANYINSTANCE | #DIDFT_AXIS :dfDIMouse2(2)\dwFlags = 0 
dfDIMouse2(3)\pguid = GUID_Button :dfDIMouse2(3)\dwOfs = #DIMOFS_BUTTON0 :dfDIMouse2(3)\dwType = #DIDFT_ANYINSTANCE | #DIDFT_BUTTON :dfDIMouse2(3)\dwFlags = 0 
dfDIMouse2(4)\pguid = GUID_Button :dfDIMouse2(4)\dwOfs = #DIMOFS_BUTTON1 :dfDIMouse2(4)\dwType = #DIDFT_ANYINSTANCE | #DIDFT_BUTTON :dfDIMouse2(4)\dwFlags = 0 
dfDIMouse2(5)\pguid = GUID_Button :dfDIMouse2(5)\dwOfs = #DIMOFS_BUTTON2 :dfDIMouse2(5)\dwType = #DIDFT_OPTIONAL | #DIDFT_ANYINSTANCE | #DIDFT_BUTTON :dfDIMouse2(5)\dwFlags = 0 
dfDIMouse2(6)\pguid = GUID_Button :dfDIMouse2(6)\dwOfs = #DIMOFS_BUTTON3 :dfDIMouse2(6)\dwType = #DIDFT_OPTIONAL | #DIDFT_ANYINSTANCE | #DIDFT_BUTTON :dfDIMouse2(6)\dwFlags = 0 
dfDIMouse2(7)\pguid = GUID_Button :dfDIMouse2(7)\dwOfs = #DIMOFS_BUTTON4 :dfDIMouse2(7)\dwType = #DIDFT_OPTIONAL | #DIDFT_ANYINSTANCE | #DIDFT_BUTTON :dfDIMouse2(7)\dwFlags = 0 
dfDIMouse2(8)\pguid = GUID_Button :dfDIMouse2(8)\dwOfs = #DIMOFS_BUTTON5 :dfDIMouse2(8)\dwType = #DIDFT_OPTIONAL | #DIDFT_ANYINSTANCE | #DIDFT_BUTTON :dfDIMouse2(8)\dwFlags = 0 
dfDIMouse2(9)\pguid = GUID_Button :dfDIMouse2(9)\dwOfs = #DIMOFS_BUTTON6 :dfDIMouse2(9)\dwType = #DIDFT_OPTIONAL | #DIDFT_ANYINSTANCE | #DIDFT_BUTTON :dfDIMouse2(9)\dwFlags = 0 
dfDIMouse2(10)\pguid = GUID_Button :dfDIMouse2(10)\dwOfs = #DIMOFS_BUTTON7 :dfDIMouse2(10)\dwType = #DIDFT_OPTIONAL | #DIDFT_ANYINSTANCE | #DIDFT_BUTTON :dfDIMouse2(10)\dwFlags = 0 ;} 

c_dfDIMouse2.DIDATAFORMAT ;{ 

c_dfDIMouse2\dwSize = SizeOf(DIDATAFORMAT) 
c_dfDIMouse2\dwObjSize = SizeOf(DIOBJECTDATAFORMAT) 
c_dfDIMouse2\dwFlags = #DIDF_RELAXIS
;c_dfDIMouse2\dwFlags = #DIDF_ABSAXIS 
c_dfDIMouse2\dwDataSize = 20 
c_dfDIMouse2\dwNumObjs = 11 ;SizeOf(c_rgodfDIMouse2)/SizeOf(c_rgodfDIMouse2[0]) 
c_dfDIMouse2\rgodf = @dfDIMouse2() ;}

Procedure FindPartWin(part$)
  rslt=GetWindow_(GetDesktopWindow_(),#GW_CHILD) 
  Repeat 
    tlt$=Space(999) : GetWindowText_(rslt,tlt$,999) 
    If FindString(tlt$,part$,1)<>0 And IsWindowVisible_(rslt)=#True 
      wnukn=rslt 
    Else 
      rslt=GetWindow_(rslt,#GW_HWNDNEXT) 
    EndIf 
  Until rslt=0 Or wnukn<>0 
  ProcedureReturn wnukn 
EndProcedure
hwnd.l = FindPartWin("BF2") ; the name of the .exe for the app handle I want
;w$ = GetWindowTitleEx(hwnd)

Global wp.WINDOWPLACEMENT
wp.WINDOWPLACEMENT 
wp\Length = SizeOf(WINDOWPLACEMENT) 
GetWindowPlacement_(hwnd, @wp)
wdth = wp\rcNormalPosition\right - wp\rcNormalPosition\left 
hght = wp\rcNormalPosition\bottom - wp\rcNormalPosition\top

Procedure.l hInst() 
  !MOV Eax, dword[_PB_Instance] 
  ProcedureReturn 
EndProcedure 

Dim keys.b(255) 
MouseState.DIMOUSESTATE2

DINPUT_DLL = OpenLibrary(#PB_Any,"DINPUT8.DLL") 
If CallFunction(DINPUT_DLL,"DirectInput8Create",hInst(),#DIRECTINPUT_VERSION,IID_IDirectInput8A,@*DirectInput8.IDirectInput8A,#Null) = #DI_OK
  If *DirectInput8\CreateDevice(GUID_SysKeyboard, @*DI_Keyb.IDirectInputDevice8A, #Null) = #DI_OK 
    If *DI_Keyb\SetCooperativeLevel(hwnd, #DISCL_NONEXCLUSIVE | #DISCL_BACKGROUND) = #DI_OK 
      If *DI_Keyb\SetDataFormat(@c_dfDIKeyboard) = #DI_OK 
        If *DI_Keyb\Acquire() = #DI_OK 
          ;Mouse 
          If *DirectInput8\CreateDevice(GUID_SysMouse, @*DI_Mouse.IDirectInputDevice8A, #Null) = #DI_OK 
            If *DI_Mouse\SetCooperativeLevel(hwnd, #DISCL_NONEXCLUSIVE | #DISCL_BACKGROUND) = #DI_OK
            ;If *DI_Mouse\SetCooperativeLevel(hwnd, #DISCL_NONEXCLUSIVE | #DISCL_FOREGROUND) = #DI_OK
            ;If *DI_Mouse\SetCooperativeLevel(hwnd, #DISCL_EXCLUSIVE | #DISCL_BACKGROUND) = #DI_OK
            ;If *DI_Mouse\SetCooperativeLevel(hwnd, #DISCL_EXCLUSIVE | #DISCL_FOREGROUND) = #DI_OK
             If *DI_Mouse\SetDataFormat(@c_dfDIMouse2) = #DI_OK 
                If *DI_Mouse\Acquire() = #DI_OK
                mintMouseX = 0
                mintMouseY = 0
                Repeat
                  *DI_Keyb\GetDeviceState(256, @keys() ) ;256 = SizeOf(keys()) 
                    *DI_Mouse\GetDeviceState(SizeOf(DIMOUSESTATE2), @MouseState )
                    If MouseState\rgbButtons[MOUSEBUTTON_LEFT]
                    ; convert from relative to absolute coords ???
                    mintMouseX = mintMouseX + @MouseState\lx
                    mintMouseY = mintMouseY + @MouseState\ly
                    Debug mintMouseX
                    EndIf
                    Until keys(#DIK_F12) & $80
                  *DI_Mouse\Unacquire() 
                EndIf 
              EndIf 
            EndIf 
            *DI_Mouse\Release() 
          EndIf 
          
          *DI_Keyb\Unacquire() 
        EndIf 
      EndIf 
    EndIf 
    *DI_Keyb\Release() 
  EndIf 
  *DirectInput8\Release() 
EndIf
The section i'm having problems with is:

Code: Select all

If MouseState\rgbButtons[MOUSEBUTTON_LEFT]
                    ; convert from relative to absolute coords ???
                    mintMouseX = mintMouseX + @MouseState\lx
                    mintMouseY = mintMouseY + @MouseState\ly
                    Debug mintMouseX
                    EndIf
and I did this thinking I was implementing some advice I received from somweher else. This advice was:

"referring To the values returned via GetDeviceState:
The mouse x,y coordinates are relative To the previous position.
IN other words, GetDeviceState doesn't Return the mouse position,
instead it returns the amount the mouse has moved since the last CALL.
But, that's okay, it works OUT the same. Simply ADD a Global POINT variable, initialize it To (0,0) For the top-left corner Or (320,240)
For the center of a 640x480 screen, then ADD the (x,y) values returned
from GetDeviceState To the (x,y) POINT variable. That way you can track
the current mouse position And send that To your menu function.
Using relative values also allows you To reposition the mouse without
worrying about where windows thinks the mouse is"

So this is what I tried to implement the advice to get the absolute coords. I'm not sure i did it correctly. I'me getting a ton of very large numbers like 126793624 or 726589734, sometimes they are negative numbers, from the debug output, and the repeat loop seems to keep running even though the left mouse button is not pressed (it starts after the button is pressed the first time but seems to keep running and the debug output seems to keep reading the mouse state). the numbers keep changing even tho the mouse button is not down. Any help or suggestions?

Thank You
theteapot
User
User
Posts: 37
Joined: Fri Sep 09, 2005 7:46 am

Post by theteapot »

I may be missing something here, but shouldn't you have it without the @ symbol because the @ symbol refers to a pointer?

Code: Select all

If MouseState\rgbButtons[MOUSEBUTTON_LEFT]
                    ; convert from relative to absolute coords ???
                    mintMouseX = mintMouseX + MouseState\lx
                    mintMouseY = mintMouseY + MouseState\ly
                    Debug mintMouseX
                    EndIf
I think you might have been mixed up between a pointer and a POINT structure.
Using PB 3.94 demo AND PROUD OF IT!!

*Goes back to little hole*
Post Reply