AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Mouse Numpad Grid

 
Reply to topic    AutoHotkey Community Forum Index -> Scripts & Functions
View previous topic :: View next topic  
Author Message
DevX



Joined: 07 Jan 2009
Posts: 43

PostPosted: Mon Dec 28, 2009 10:17 pm    Post subject: Mouse Numpad Grid Reply with quote

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

Code:

; 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
}
Back to top
View user's profile Send private message
ddk



Joined: 28 Dec 2009
Posts: 43

PostPosted: Tue Dec 29, 2009 12:27 am    Post subject: Reply with quote

Haha! That's damn interesting! Smile
Too bad I have bigger resolution, than you do, but thats a great script if made in 45mins Very Happy
Back to top
View user's profile Send private message
xXDarknessXx



Joined: 03 Sep 2009
Posts: 93

PostPosted: Mon Mar 28, 2011 5:33 pm    Post subject: Reply with quote

Upgraded your script, now it'll work with any resolution (No Multi-Monitor compatibility)

Code:
#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
Back to top
View user's profile Send private message MSN Messenger
Display posts from previous:   
Reply to topic    AutoHotkey Community Forum Index -> Scripts & Functions All times are GMT
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group