Advertisement
Mangus875

Bouncing Cat Window (Autohotkey)

May 3rd, 2024
1,393
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. CoordMode "Mouse", "Screen"
  2. CoordMode "ToolTip", "Screen"
  3. #R::Reload
  4. SetWinDelay 0
  5.  
  6. MyGui := Gui(, "")
  7. MyGui.Opt("ToolWindow -Sysmenu +AlwaysOnTop")
  8. MyGui.SetFont "s36 w700"
  9. MyGui.BackColor := "dddddd"
  10. MyGui.Add("Text", "x4 y-24", ".!.")
  11. MyGui.SetFont "s16 w400"
  12. MyGui.Add("Text", "w12 xp+16 yp+41", "^")
  13. WinSetStyle("0x800000", MyGui)
  14. MyGui.Show("w50 h40 Center NoActivate")
  15.  
  16. OnMessage(0x201, WM_MouseDown)
  17. ; OnMessage(0x202, WM_MouseUp)
  18. lastX := 0
  19. lastY := 0
  20. dx := 0
  21. dy := 0
  22. falling := false
  23. grabbed := false
  24. enableMove := true
  25.  
  26. WM_MouseDown(wParam, lParam, msg, window) {
  27.   global grabbed
  28.  
  29.   if (window != MyGui.Hwnd) {
  30.     return
  31.   }
  32.  
  33.   grabbed := true
  34.   MouseGetPos &mouseX, &mouseY
  35.   lastX := mouseX
  36.   lastY := mouseY
  37. }
  38.  
  39. ~LButton Up::MouseUp
  40. MouseUp() {
  41.   global grabbed
  42.   if grabbed {
  43.     grabbed := false
  44.     fall
  45.   }
  46. }
  47.  
  48. acc := 1.0
  49. vel := 0.0
  50. pos := 0.0
  51. fall() {
  52.     global vel
  53.     global acc
  54.     global pos
  55.   global falling
  56.   offset := 82
  57.  
  58.   falling := true
  59.  
  60.     WinGetPos ,&startPos,,, MyGui
  61.     pos := startPos
  62.  
  63.     while (abs(vel) > 0.5 or (A_ScreenHeight - abs(pos+offset) > 2)) {
  64.     if grabbed {
  65.       break
  66.     }
  67.         Sleep 1
  68.         vel += acc
  69.         pos += vel
  70.        
  71.         WinGetPos &xpos,,,, MyGui
  72.         if (pos+offset > A_ScreenHeight) {
  73.             WinMove xpos, A_ScreenHeight-offset,,, MyGui
  74.             vel := -0.8*abs(vel)
  75.         } else
  76.         WinMove xpos, pos,,, MyGui
  77.     }  
  78.     WinGetPos &endpos,,,, MyGui
  79.   if (!grabbed) {
  80.     WinMove endPos, A_ScreenHeight-offset,,, MyGui
  81.   }
  82.     vel := 0
  83.     pos := 0
  84.   SetTimer () => falling := false, -50
  85. }
  86.  
  87. sleep 100
  88. fall()
  89.  
  90. while true {
  91.   global dx
  92.   global dy
  93.   global lastX
  94.   global lastY
  95.   global grabbed
  96.  
  97.  
  98.   WinGetPos &winx, &winy,,, MyGui
  99.   MouseGetPos &x, &y
  100.   dx := x-lastX
  101.   dy := y-lastY
  102.   lastX := x
  103.   lastY := y
  104.  
  105.   if (!falling && grabbed && enableMove) {
  106.     WinMove winx+dx, winy+dy,,, MyGui
  107.   }
  108.  
  109.   sleep 0
  110. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement