Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

Mouse Numpad Grid


  • Please log in to reply
2 replies to this topic
DevX
  • Members
  • 43 posts
  • Last active: Jan 12 2011 06:44 PM
  • Joined: 07 Jan 2009
Well I made a prototype but I don't really like it, maybe someone else will.

It's a mouse clicker via numpad, with graphical grid drawn on screen to see where your going. Toy around and you'll see what I mean.

Press F2 to restart it.

Requires Gdip.ahk and 1024x768 resolution ( hey, its a prototype )

( Maybe someone can make use of the 45 minutes used to make it ) =D

; gdi+ ahk tutorial 1 written by tic (Tariq Porter)
; Requires Gdip.ahk either in your Lib folder as standard library or using #Include
;
; Tutorial to draw a single ellipse and rectangle to the screen

#SingleInstance, Force
#NoEnv
SetBatchLines, -1
CurStep := 1
NewTop := 0
NewLeft := 0



; Uncomment if Gdip.ahk is not in your standard library
#Include, Gdip.ahk

; Start gdi+
If !pToken := Gdip_Startup()
{
	MsgBox, 48, gdiplus error!, Gdiplus failed to start. Please ensure you have gdiplus on your system
	ExitApp
}
OnExit, Exit

; Set the width and height we want as our drawing area, to draw everything in. This will be the dimensions of our bitmap
Width := 1024, Height := 768

; Create a layered window (+E0x80000 : must be used for UpdateLayeredWindow to work!) that is always on top (+AlwaysOnTop), has no taskbar entry or caption
Gui, 1: -Caption +E0x80000 +LastFound +AlwaysOnTop +ToolWindow +OwnDialogs

; Show the window
Gui, 1: Show, NA

; Get a handle to this window we have created in order to update it later
hwnd1 := WinExist()

; Create a gdi bitmap with width and height of what we are going to draw into it. This is the entire drawing area for everything
hbm := CreateDIBSection(Width, Height)

; Get a device context compatible with the screen
hdc := CreateCompatibleDC()

; Select the bitmap into the device context
obm := SelectObject(hdc, hbm)

; Get a pointer to the graphics of the bitmap, for use with drawing functions
G := Gdip_GraphicsFromHDC(hdc)

; Set the smoothing mode to antialias = 4 to make shapes appear smother (only used for vector drawing and filling)
Gdip_SetSmoothingMode(G, 4)

; Create a fully opaque red brush (ARGB = Transparency, red, green, blue) to draw a circle
pBrush := Gdip_BrushCreateSolid(0xffff0000)
pPen := Gdip_CreatePen(0xff00ff00, 1)
; Fill the graphics of the bitmap with an ellipse using the brush created
; Filling from coordinates (100,50) an ellipse of 200x300
;Gdip_FillEllipse(G, pBrush, 100, 50, 200, 300)

Gdip_DrawLine(G, pPen,  Floor(Width/3), 0,  Floor(Width/3), 768)
Gdip_DrawLine(G, pPen, Floor(Width/3*2), 0, Floor(Width/3*2), 768)

Gdip_DrawLine(G, pPen, 0,  Floor(Height/3), 1024,  Floor(Height/3))
Gdip_DrawLine(G, pPen, 0,  Floor(Height/3*2), 1024,  Floor(Height/3*2))

; Delete the brush as it is no longer needed and wastes memory
;Gdip_DeleteBrush(pBrush)

; Update the specified window we have created (hwnd1) with a handle to our bitmap (hdc), specifying the x,y,w,h we want it positioned on our screen
; So this will position our gui at (0,0) with the Width and Height specified earlier
UpdateLayeredWindow(hwnd1, hdc, 0, 0, Width, Height)

SelectObject(hdc, obm)
DeleteObject(hbm)
DeleteDC(hdc)
Gdip_DeleteGraphics(G)
Return

;#######################################################################

Exit:
; gdi+ may now be shutdown on exiting the program
Gdip_Shutdown(pToken)
ExitApp
Return

f2::reload
NumPad1::SelectWindow(1)
NumPad2::SelectWindow(2)
NumPad3::SelectWindow(3)
NumPad4::SelectWindow(4)
NumPad5::SelectWindow(5)
NumPad6::SelectWindow(6)
NumPad7::SelectWindow(7)
NumPad8::SelectWindow(8)
NumPad9::SelectWindow(9)
esc::Gui, 1: hide
f1::Gui, 1: show, +NoActivate


SelectWindow(Window)
{
  global
  If (CurStep == 1)
  {
    NewBoxWidth := 343
    NewBoxHeight := 256
  }
  else if (CurStep == 2)
  {
    NewBoxWidth := 114
    NewBoxHeight := 86
  }
  else if (CurStep == 3)
  {
    NewBoxWidth := 39
    NewBoxHeight := 29
  }
  else if (CurStep == 4)
  {
    NewBoxWidth := 12
    NewBoxHeight := 9
  }
  if (CurStep == 5)
  {
    ClickTheButton()
    CurStep := 1
    Gui, 1: Destroy
    return
  }



  if (Window == 1)
  {
    NewTop := NewTop + (NewBoxHeight * 2)
    NewLeft := NewLeft
  }

  if (Window == 2)
  {
    NewTop := NewTop + (NewBoxHeight * 2)
    NewLeft := NewLeft + NewBoxWidth
  }

  if (Window == 3)
  {
    NewTop := NewTop + (NewBoxHeight * 2)
    NewLeft := NewLeft + (NewBoxWidth * 2)
  }

  if (Window == 4)
  {
    NewTop := NewTop + NewBoxHeight
    NewLeft := NewLeft
  }

  if (Window == 5)
  {
    NewTop := NewTop + NewBoxHeight
    NewLeft := NewLeft + NewBoxWidth
  }

  if (Window == 6)
  {
    NewTop := NewTop + NewBoxHeight
    NewLeft := NewLeft + (NewBoxWidth * 2)
  }

  if (Window == 7)
  {
    NewTop := NewTop
    NewLeft := NewLeft
  }

  if (Window == 8)
  {
    NewTop := NewTop
    NewLeft := NewLeft + (NewBoxWidth)
  }

  if (Window == 9)
  {
    NewTop := NewTop
    NewLeft := NewLeft + (NewBoxWidth * 2)
  }


  CurStep += 1
  ;MsgBox % NewBoxWidth . " - " . NewBoxHeight . " - " . NewTop . " - " . NewLeft . " --- " . CurStep
  DrawNewBox()
}

DrawNewBox()
{
  global
  Gui, 1: Destroy
  Gui, 1: -Caption +E0x80000 +LastFound +AlwaysOnTop +ToolWindow +OwnDialogs
  Gui, 1: Show, NA
  hwnd1 := WinExist()
  hbm := CreateDIBSection(Width, Height)
  hdc := CreateCompatibleDC()
  obm := SelectObject(hdc, hbm)
  G := Gdip_GraphicsFromHDC(hdc)
  Gdip_SetSmoothingMode(G, 4)


  ; Box Borders
  
  ; Top
  if (NewTop > 0)
    Gdip_DrawLine(G, pPen, NewLeft, NewTop, NewLeft + NewBoxWidth, NewTop)
  ; Left
  if (NewLeft > 0)
    Gdip_DrawLine(G, pPen, NewLeft, NewTop, NewLeft, NewTop + NewBoxHeight)
  ; Bottom
  if ( (NewTop + NewBoxHeight) <= 768 )
    Gdip_DrawLine(G, pPen, NewLeft, NewTop + NewBoxHeight, NewLeft + NewBoxWidth, NewTop + NewBoxHeight)
  ; Right
  if ( (NewLeft + NewBoxWidth) <= 1024 )
    Gdip_DrawLine(G, pPen, NewLeft + NewBoxWidth, NewTop, NewLeft + NewBoxWidth, NewTop + NewBoxHeight)
    
  ; Inside Box
  
  ; Horiz
  Gdip_DrawLine(G, pPen, NewLeft, NewTop + ( NewBoxHeight / 3 ), NewLeft + NewBoxWidth, NewTop + ( NewBoxHeight / 3 ) )
  Gdip_DrawLine(G, pPen, NewLeft, NewTop + ( ( NewBoxHeight / 3 ) * 2 ), NewLeft + NewBoxWidth, NewTop + ( ( NewBoxHeight / 3 ) * 2) )
  ; Vert
  Gdip_DrawLine(G, pPen, NewLeft + ( NewBoxWidth / 3 ), NewTop, NewLeft + ( NewBoxWidth / 3 ), NewTop + NewBoxHeight )
  Gdip_DrawLine(G, pPen, NewLeft + ( ( NewBoxWidth / 3 ) * 2 ), NewTop, NewLeft + ( ( NewBoxWidth / 3 ) * 2 ),  NewTop + NewBoxHeight )
  

  UpdateLayeredWindow(hwnd1, hdc, 0, 0, Width, Height)
  
  SelectObject(hdc, obm)
  DeleteObject(hbm)
  DeleteDC(hdc)
  Gdip_DeleteGraphics(G)
  Gui, 1: Show, NA
}

ClickTheButton()
{
  global
  ;MsgBox % NewLeft + 6 . " - " . NewTop + 4
  MouseClick, Left, NewLeft, NewTop, 1, 0
}


ddk
  • Members
  • 43 posts
  • Last active: Oct 12 2010 11:03 PM
  • Joined: 28 Dec 2009
Haha! That's damn interesting! :)
Too bad I have bigger resolution, than you do, but thats a great script if made in 45mins :D

DarkVamprism
  • Members
  • 125 posts
  • Last active: Apr 25 2017 10:28 AM
  • Joined: 03 Sep 2009
Upgraded your script, now it'll work with any resolution (No Multi-Monitor compatibility)

#NoEnv
#SingleInstance, force
CoordMode, Mouse
SetBatchLines -1
SetMouseDelay -1

#Include, Gdip.ahk 

; Start gdi+ 
If !pToken := Gdip_Startup() 
{ 
   MsgBox, 48, gdiplus error!, Gdiplus failed to start. Please ensure you have gdiplus on your system 
   ExitApp 
} 
OnExit, Exit 
return

^Numpad0::
   KeyMouseToggle := !KeyMouseToggle
   if KeyMouseToggle
   {
      Gui, 1: -Caption +E0x80000 +LastFound +AlwaysOnTop +ToolWindow +OwnDialogs 
      Gui, 1: Show, NA 
      hwnd1 := WinExist() 
      hbm := CreateDIBSection(A_ScreenWidth, A_ScreenHeight) 
      hdc := CreateCompatibleDC()
      obm := SelectObject(hdc, hbm)
      G := Gdip_GraphicsFromHDC(hdc)
      Gdip_SetSmoothingMode(G, 4)
      pBrush := Gdip_BrushCreateSolid(0xffff0000) 
      pPen := Gdip_CreatePen(0xff00ff00, 1) 
      Gdip_DrawLine(G, pPen,  Floor(A_ScreenWidth/3), 0,  Floor(A_ScreenWidth/3), A_ScreenHeight) 
      Gdip_DrawLine(G, pPen, Floor(A_ScreenWidth/3*2), 0, Floor(A_ScreenWidth/3*2), A_ScreenHeight) 
      Gdip_DrawLine(G, pPen, 0,  Floor(A_ScreenHeight/3), A_ScreenWidth,  Floor(A_ScreenHeight/3)) 
      Gdip_DrawLine(G, pPen, 0,  Floor(A_ScreenHeight/3*2), A_ScreenWidth,  Floor(A_ScreenHeight/3*2))
      UpdateLayeredWindow(hwnd1, hdc, 0, 0, A_ScreenWidth, A_ScreenHeight) 
      SelectObject(hdc, obm) 
      DeleteObject(hbm) 
      DeleteDC(hdc) 
      Gdip_DeleteGraphics(G)
      
      init()
   }
   else
   {
      Gui, 1: Destroy
   }
return

#if KeyMouseToggle
   NumPad1::SelectWindow(1) 
   NumPad2::SelectWindow(2) 
   NumPad3::SelectWindow(3) 
   NumPad4::SelectWindow(4) 
   NumPad5::SelectWindow(5) 
   NumPad6::SelectWindow(6) 
   NumPad7::SelectWindow(7) 
   NumPad8::SelectWindow(8) 
   NumPad9::SelectWindow(9)
#if

Init()
{
   global
   currX := 0
   currY := 0
   currW := A_ScreenWidth
   currH := A_ScreenHeight
}

SelectWindow(Win)
{
   global
   currW := currW / 3
   currH := currH / 3
      
   if (Win >= 1 and Win <= 3) 
   { 
      currY := currY + (currH * 2)
   }
   else if (Win >= 4 and Win <= 6) 
   { 
      currY := currY + currH
   }
   else if (Win >= 7 and Win <= 9) 
   { 
      currY := currY
   }
   
   if (Win == 1 || Win == 4 || Win == 7) 
   { 
      currX := currX
   }
   else if (Win == 2 or Win == 5 or Win == 8)
   { 
      currX := currX + currW
   }
   else if (Win == 3 or Win == 6 or Win == 9)
   { 
      currX := currX + (currW * 2) 
   }
   
   if (CurStep == 5) 
   { 
      CurStep := 0
      KeyMouseToggle := false
      Gui, 1: Destroy 
      ClickTheButton()
      return 
   } 
   
   CurStep++
   DrawNewBox()
}

DrawNewBox() 
{ 
  global 
  Gui, 1: Destroy 
  Gui, 1: -Caption +E0x80000 +LastFound +AlwaysOnTop +ToolWindow +OwnDialogs 
  Gui, 1: Show, NA 
  hwnd1 := WinExist() 
  hbm := CreateDIBSection(A_ScreenWidth, A_ScreenHeight) 
  hdc := CreateCompatibleDC() 
  obm := SelectObject(hdc, hbm) 
  G := Gdip_GraphicsFromHDC(hdc) 
  Gdip_SetSmoothingMode(G, 4) 

   if (currY > 0) 
      Gdip_DrawLine(G, pPen, currX, currY, currX + currW, currY) 
   if (currX > 0) 
      Gdip_DrawLine(G, pPen, currX, currY, currX, currY + currH) 
   if ( (currY + currH) <= A_ScreenHeight ) 
      Gdip_DrawLine(G, pPen, currX, currY + currH, currX + currW, currY + currH) 
   if ( (currX + currW) <= A_ScreenWidth )
      Gdip_DrawLine(G, pPen, currX + currW, currY, currX + currW, currY + currH) 

  Gdip_DrawLine(G, pPen, currX, currY + ( currH / 3 ), currX + currW, currY + ( currH / 3 ) ) 
  Gdip_DrawLine(G, pPen, currX, currY + ( ( currH / 3 ) * 2 ), currX + currW, currY + ( ( currH / 3 ) * 2) ) 

  Gdip_DrawLine(G, pPen, currX + ( currW / 3 ), currY, currX + ( currW / 3 ), currY + currH ) 
  Gdip_DrawLine(G, pPen, currX + ( ( currW / 3 ) * 2 ), currY, currX + ( ( currW / 3 ) * 2 ),  currY + currH ) 
  

  UpdateLayeredWindow(hwnd1, hdc, 0, 0, A_ScreenWidth, A_ScreenHeight) 
  
  SelectObject(hdc, obm) 
  DeleteObject(hbm) 
  DeleteDC(hdc) 
  Gdip_DeleteGraphics(G) 
  Gui, 1: Show, NA 
}

ClickTheButton() 
{ 
  global
  MouseClick, Left, currX, currY, 1, 0 
}

Exit: 
   Gdip_Shutdown(pToken) 
ExitApp

Edit: I should probably mension you use Ctrl+Numpad0 to open\close the grid