Advertisement
name22

MouseMeter 1.2

Jun 29th, 2011
285
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
AutoIt 4.29 KB | None | 0 0
  1. #include <GUIConstantsEx.au3>
  2. #include <WindowsConstants.au3>
  3. #include <Misc.au3>
  4.  
  5. ; - Author: name22 (www.autoit.de)
  6.  
  7. $iGUIWidth = 165
  8. $iGUIHeight = 290
  9. $iX = @DesktopWidth - $iGUIWidth + $iGUIWidth / 2
  10. $iY = @DesktopHeight - $iGUIHeight + $iGUIHeight / 2
  11.  
  12. $iDeskDiag = IniRead("Data.ini", "Const", "DeskDiagInch", "Error")
  13. If $iDeskDiag = "Error" Then
  14.     $iDeskDiag = InputBox("Bildschirmdiagonale", "Länge der Bildschirmdiagonale in Zoll: ", "17")
  15.     If StringReplace($iDeskDiag, " ", "") = "" Then Exit
  16.     IniWrite("Data.ini", "Const", "DeskDiagInch", $iDeskDiag)
  17. EndIf
  18.  
  19. $PPI = Sqrt(@DesktopWidth ^ 2 + @DesktopHeight ^ 2) / $iDeskDiag
  20. $PPCm = Sqrt(@DesktopWidth ^ 2 + @DesktopHeight ^ 2) / ($iDeskDiag * 2.54)
  21.  
  22. $hWnd = GUICreate("MouseMeter", $iGUIWidth, $iGUIHeight, $iX - $iGUIWidth / 2, $iY - $iGUIHeight / 2, $WS_POPUP, $WS_EX_TOPMOST)
  23. GUISetBkColor(0x545454, $hWnd)
  24. $Label1 = GUICtrlCreateLabel("Zurückgelegte Strecke:", 10, 10, 155)
  25. GUICtrlSetFont(-1, 10)
  26. GUICtrlSetColor(-1, 0xFFFFFF)
  27. $Label2 = GUICtrlCreateLabel("Zentimeter:", 10, 40)
  28. GUICtrlSetFont(-1, 10)
  29. GUICtrlSetColor(-1, 0xFFFFFF)
  30. $Label3 = GUICtrlCreateLabel("0", 10, 55, 70)
  31. GUICtrlSetFont(-1, 10)
  32. GUICtrlSetColor(-1, 0xFFFFFF)
  33. $Label4 = GUICtrlCreateLabel("Meter:", 10, 75)
  34. GUICtrlSetFont(-1, 10)
  35. GUICtrlSetColor(-1, 0xFFFFFF)
  36. $Label5 = GUICtrlCreateLabel("0", 10, 90, 70)
  37. GUICtrlSetFont(-1, 10)
  38. GUICtrlSetColor(-1, 0xFFFFFF)
  39. $Label6 = GUICtrlCreateLabel("Inch:", 10, 110)
  40. GUICtrlSetFont(-1, 10)
  41. GUICtrlSetColor(-1, 0xFFFFFF)
  42. $Label7 = GUICtrlCreateLabel("0", 10, 125, 70)
  43. GUICtrlSetFont(-1, 10)
  44. GUICtrlSetColor(-1, 0xFFFFFF)
  45. $Label8 = GUICtrlCreateLabel("Pixel:", 10, 145)
  46. GUICtrlSetFont(-1, 10)
  47. GUICtrlSetColor(-1, 0xFFFFFF)
  48. $Label9 = GUICtrlCreateLabel("0", 10, 160, 70)
  49. GUICtrlSetFont(-1, 10)
  50. GUICtrlSetColor(-1, 0xFFFFFF)
  51. $Label10 = GUICtrlCreateLabel("Geschwindigkeit:", 10, 180, 155)
  52. GUICtrlSetFont(-1, 10)
  53. GUICtrlSetColor(-1, 0xFFFFFF)
  54. GUICtrlSetFont(-1, 10)
  55. $Label11 = GUICtrlCreateLabel("Meter/Sekunde:", 10, 205)
  56. GUICtrlSetFont(-1, 10)
  57. GUICtrlSetColor(-1, 0xFFFFFF)
  58. $Label12 = GUICtrlCreateLabel("0", 10, 220, 70)
  59. GUICtrlSetFont(-1, 10)
  60. GUICtrlSetColor(-1, 0xFFFFFF)
  61. $Label13 = GUICtrlCreateLabel("Meter/Sekunde (Durchschnitt):", 10, 235, 100, 50)
  62. GUICtrlSetFont(-1, 10)
  63. GUICtrlSetColor(-1, 0xFFFFFF)
  64. $Label14 = GUICtrlCreateLabel("0", 10, 265, 70)
  65. GUICtrlSetFont(-1, 10)
  66. GUICtrlSetColor(-1, 0xFFFFFF)
  67. $Reset = GUICtrlCreateButton("Zurücksetzen", 90, 75, 70, 25)
  68. $Exit = GUICtrlCreateButton("Beenden", 90, 105, 70, 25)
  69. GUISetState()
  70.  
  71. WinSetTrans($hWnd, "", 200)
  72.  
  73. $aPosOld = MouseGetPos()
  74. $iDistance = 0
  75.  
  76. $iTime = TimerInit()
  77. AdlibRegister("_Update", 30)
  78.  
  79. While 1
  80.     $nMsg = GUIGetMsg(1)
  81.     Switch $nMsg[0]
  82.         Case $GUI_EVENT_CLOSE, $Exit
  83.             Exit
  84.         Case $Reset
  85.             $iTime = TimerInit()
  86.             $iDistance = 0
  87.             _Update()
  88.         Case $GUI_EVENT_PRIMARYDOWN
  89.             _SetPos()
  90.     EndSwitch
  91. WEnd
  92.  
  93. Func _Update()
  94.     $iTime2 = TimerInit()
  95.     $aPosNew = MouseGetPos()
  96.     $iDiff = _GetPointsDistance($aPosOld[0], $aPosOld[1], $aPosNew[0], $aPosNew[1])
  97.     $iDistance += $iDiff
  98.     GUICtrlSetData($Label3, Floor($iDistance / $PPCm))
  99.     GUICtrlSetData($Label5, Floor($iDistance / $PPCm / 100))
  100.     GUICtrlSetData($Label7, Floor($iDistance / $PPI))
  101.     GUICtrlSetData($Label9, Floor($iDistance))
  102.     GUICtrlSetData($Label12, Round(($iDiff / $PPCm / 100) / (TimerDiff($iTime2) / 1000), 4))
  103.     GUICtrlSetData($Label14, Round(($iDistance / $PPCm / 100) / (TimerDiff($iTime) / 1000), 4))
  104.     $aPosOld[0] = $aPosNew[0]
  105.     $aPosOld[1] = $aPosNew[1]
  106. EndFunc   ;==>_Update
  107.  
  108. Func _SetPos()
  109.     Sleep(200)
  110.     While _IsPressed("01")
  111.         $aPosMouse = MouseGetPos()
  112.  
  113.         $iDiffX = $iX - $aPosMouse[0]
  114.         If $iDiffX < 0 Then $iDiffX *= -1
  115.         $iDiffY = $iY - $aPosMouse[1]
  116.         If $iDiffY < 0 Then $iDiffY *= -1
  117.  
  118.         $iSpeedX = $iDiffX / 10
  119.         $iSpeedY = $iDiffY / 10
  120.  
  121.         If $iX < $aPosMouse[0] Then
  122.             $iX += $iSpeedX
  123.         ElseIf $iX > $aPosMouse[0] Then
  124.             $iX -= $iSpeedX
  125.         EndIf
  126.         If $iY < $aPosMouse[1] Then
  127.             $iY += $iSpeedY
  128.         ElseIf $iY > $aPosMouse[1] Then
  129.             $iY -= $iSpeedY
  130.         EndIf
  131.  
  132.         WinMove($hWnd, "", $iX - $iGUIWidth / 2, $iY - $iGUIHeight / 2)
  133.         Sleep(30)
  134.     WEnd
  135. EndFunc   ;==>_SetPos
  136.  
  137. Func _GetPointsDistance($iPointX1, $iPointY1, $iPointX2, $iPointY2)
  138.     Return Sqrt(($iPointX1 - $iPointX2) ^ 2 + ($iPointY1 - $iPointY2) ^ 2)
  139. EndFunc   ;==>_GetPointsDistance
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement