BlitzCoder Essentials
•
Home Page
•
About BlitzCoder
•
Contributors
•
Terms of Use
•
Email Us
Main Areas
•
BlitzCoder Chat
•
Discussions
•
Articles/Tutorials
•
Code Database
•
Link Database
•
Showcase Area
•
Worklogs
•
Competitions
Special Areas
•
Undocumented
Other Blitz Sites
•
Blitz Basic Home
•
Blitz Showcase
•
BlitzPlay Library
Forum Login
Username:
Password:
•
Register Now!
BlitzCoder Code Archives Page
Main Codes Page
"Universal mouse speed"
, by thechange
Makes the mouse move with the same speed on all display resolutions.
Code
; Demonstrates how to make mouse speed independent of resolution. ; So mouse moves just as fast on 320x200 or 1600x1200. Const ResX = 1600 ; Change these to test the speed Const ResY = 1200 Graphics ResX , ResY , 0 , 1 ;<-- Const DefaultSpeedX = 640 ; Speed will be matched to the speed of the mouse Const DefaultSpeedY = 480 ; when the resolution is 640x480. ; It's simply scaling from one range to another. ; ; Default resolution ; ; |<------------->| ; . ||--.. ; x Speed Factor . ||-.. ; . ||--.. ; |<------------------------------->| ; ; Current resolution ; Const MouseFactorX# = Float ResX / DefaultSpeedX ; Speed factor Const MouseFactorY# = Float ResY / DefaultSpeedY MoveMouse ResX / 2 , ResY / 2 ; Start centered MousePosX = MouseX() MousePosY = MouseY() SetBuffer BackBuffer() Repeat ; Calculate where the mouse should be (old scale -> new scale) MousePosX = MousePosX + MouseXSpeed() * MouseFactorX MousePosY = MousePosY + MouseYSpeed() * MouseFactorY ; Default resolution ; ; |<---o<>o------>| ; . . . ||--.. ; x Speed Factor . . . ||-.. ; . . . ||--.. ; |<---o<--->o--------------------->| ; / ; / Current resolution ; / ; New mouse movement ; Place mouse where it should have been MoveMouse MousePosX , MousePosY DrawPointer MouseX() , MouseY() Flip Cls Until MouseHit( 1 ) Or KeyHit( 1 ) End Function DrawPointer ( X , Y ) Line X,Y , X+10,Y Line X+10,Y , X,Y+10 Line X,Y+10 , X,Y End Function ;-->
Copyright(c) 2000-2004, BlitzCoder. All Rights Reserved.
Code software created by Krylar's Kreations