InGame v2.0

Post gaming related scripts
_3D_
Posts: 277
Joined: 29 Jan 2014, 14:40

InGame v2.0

24 Feb 2014, 11:00

The Beginning from old forum https://autohotkey.com/board/topic/93246-ingame-scripts-howto/
This days I read careful changes in v1.1.14.03 and in v2.0 and my opinion moving to C like syntax is right way.
Now all next examples will be in v2.0 ONLY

Welcome - I will continue to evolve InGame post here - v2.0 coming from AHK v2.0 (still alpha but the future).
Table of contents - Inspired by Helgef

Last edited by _3D_ on 24 Mar 2020, 08:15, edited 13 times in total.
AHKv2.0 alpha forever.
_3D_
Posts: 277
Joined: 29 Jan 2014, 14:40

InGame v2.0 (Small functions)

24 Feb 2014, 12:28

Code: Select all

__(v, p:= 2, c:= "0") ;Adding srting (c) (p) times at the front of (v)
{ Loop p - StrLen(v)
    v:= c v
  return v
} ;===============================================
As you see - no so difference with 1.1.14 and L

Code: Select all

;Usage:
__(2, 5, ".") ;....2
__(2, 5, "_") ;____2
__(2, 5)      ;00002
Last edited by _3D_ on 09 May 2015, 00:14, edited 1 time in total.
AHKv2.0 alpha forever.
_3D_
Posts: 277
Joined: 29 Jan 2014, 14:40

InGame v2.0 (Small functions)

24 Feb 2014, 12:36

Code: Select all

;DD_ToolTip("Hide in 3000 ms", 3000)
;DD_ToolTip("Stay")
;DD_ToolTip() ;Hide
DD_ToolTip(text:= "", time:= 0) ;timedFunction
{ ToolTip % text
  SetTimer, LABEL_DD_ToolTip,% time? -time:"Off" ;(-) run only once
  return
  LABEL_DD_ToolTip: 
    ToolTip
  RETURN
} ;===============================================
LOL only : added
Usage at comments.
Last edited by _3D_ on 09 May 2015, 00:14, edited 2 times in total.
AHKv2.0 alpha forever.
_3D_
Posts: 277
Joined: 29 Jan 2014, 14:40

InGame v2.0 (SleepThrow)

24 Feb 2014, 12:57

EDITED
Due to any command may be function Using user defined Sleep(arg) not usable.

Code: Select all

;Sleep function - conditional execution
;
;{ try { ...
;        SleepThrow(ms)
;        ...
;      }
;  catch
;        return    
;}
!Space::terminateRUN:=!terminateRUN ;conditional execution control
SleepThrow(tm)
{ global terminateRUN
  if tm, Sleep(tm)  ;I like oneline IF
  if terminateRUN, throw terminateRUN
  return !terminateRUN
} ;===============================================
At last - used technic allows conditional execution of given code depend from user.
As I explain more algorithms used InGame running next style:
action
sleep
action
sleep
action
and in 99% of time script in sleep
Your code MUST be in try { ... } block and catch return after.
The code terminate current execution and return to caller.

If terminateRUN not exist and/or try/catch not used SleepThrow(tm) run as Sleep(tm) (except SleepThrow(0) that will run as nothing "NOP" and different from Sleep(0)).
Last edited by _3D_ on 02 Dec 2019, 13:19, edited 4 times in total.
AHKv2.0 alpha forever.
_3D_
Posts: 277
Joined: 29 Jan 2014, 14:40

InGame v2.0 Concatenate Long Strings [SOLUTION]

24 Feb 2014, 18:10

I start converting Gdip v1.45 by tic (Tariq Porter) to AHKv2.0
Sorry if I don`t find HowTo concatenate strings but [SOLUTION].

In v2.0 not possible to use unquoted strings.

Code: Select all

;v1.0/v1.1/L style
Var:=
(Ltim Join
First Line.
Second Line.
Third Line.
) ;Var is "First Line.Second Line.Third Line."
How this will be in v2.0 if no unquoted strings?

Code: Select all

;v2.0 style
Var:= "" ;fake init
. "First Line." ;dot space string
. "Second Line."
. "Third Line." ;Var is "First Line.Second Line.Third Line."
It is useful when mcode
I try to post example from Gdip code converted to v2.0 but view good only in preview
NEXT CODE IS JUST EXAMPLE AND MCODE IS NOT REAL

Code: Select all

;MCODE IS NOT REAL
if !A_Is64bitOS ; x86 machine code (A_Is64bitOS exist even not commented at web documentation)
MCode_PixelateBitmap:= ""
  . "558BEC83EC3C8B4514538B5D1C99F7FB56578BC88955EC89"
  . "397DE80F8E160100008BCB0FAFCB894DCC33C08945F88945"
  . "8D0CB80FAFCB03CA895DD08BD1895DE40FB6441603014514"
  . "4DD075C98B4DCC8B451499F7F98945148B451C99F7F98945"
else ; x64 machine code
MCode_PixelateBitmap:= ""
  . "4489442418488954241048894C2408535556574154415541"
  . "448994248800000085C00F8E9D020000418BC04533E4458B"
  . "4C8B5C24784585ED0F8E1A010000458BF1418BFD48897C24"
  . "C148984C8D441802498BD9498BD04D8BD90FB642010FB64A"
NOW IMPORTANT:
1.If you start concatenate at next line use fake empty string ""
2.Next line start with dot space
3.Then string
4.Repeat 2-3 :P
Last edited by _3D_ on 09 May 2015, 00:17, edited 1 time in total.
AHKv2.0 alpha forever.
_3D_
Posts: 277
Joined: 29 Jan 2014, 14:40

InGame v2.0 GDIP v1.45 AHK v2.0

26 Feb 2014, 19:27

The original Gdip v1.45 by tic http://www.autohotkey.net/~tic/Gdip.ahk
Gdip_All by Rseding91 http://www.autohotkey.net/~Rseding91/Gd ... ip_All.ahk
and post http://www.autohotkey.com/board/topic/2 ... 45-by-tic/

Due to I use 32bit and 64bit OSes I got Gdip_All.
There 3 cases:
1. 32 bit AHK over 32 bit OS (A_PtrSize = 4)
2. 32 bit AHK over 64 bit OS (A_PtrSize = 4)
3. 64 bit AHK over 64 bit OS (A_PtrSize = 8)

I correct usage of A_PtrSize to (A_PtrSize = 8)? "UPtr": "UInt" instead of A_PtrSize? "UPtr": "UInt"
Gdip_All_Corrected by _3D_ http://ahkscript.org/boards/download/fi ... iew&id=177
now the same script work perfect at any bit AHK type over any bit OS

In my first post I said that will post examples ONLY in AHKv2.0 me need and Gdip for AHK v2.0
Gdip_All_Corrected_AHKv2.0 by _3D_ http://ahkscript.org/boards/download/fi ... iew&id=178
Changes:
1. syntax for arguments
2. syntax for IF
3. syntax after StrSplit
4. rewrite after RegExMatch (it is new convention)

EDIT: I still testing Gdip_AHKv2.0 with "Ptr" instead of (A_PtrSize = 8)? "UPtr": "UInt"
Attachments
Gdip_v1.45[tic]_All[Rseding91][_3D_]_AHKv2.0.zip
(19.41 KiB) Downloaded 839 times
Gdip_v1.45[tic]_All[Rseding91][_3D_].zip
(19.12 KiB) Downloaded 798 times
Last edited by _3D_ on 14 Mar 2014, 15:01, edited 1 time in total.
AHKv2.0 alpha forever.
_3D_
Posts: 277
Joined: 29 Jan 2014, 14:40

InGame v2.0 Gdip_AHKv2.0 DD_GetPixel

26 Feb 2014, 19:54

Next example used AHKv2.0
It is the same logic like http://www.autohotkey.com/board/topic/9 ... ntry589602

Code: Select all

#SingleInstance, Force
CoordMode, Mouse, Screen
CoordMode, Pixel, Screen

  GUI_ACTIVE:= 1
  
  pToken:= Gdip_Startup()
  Gui, -Caption +E0x80000 +LastFound +AlwaysOnTop +ToolWindow +OwnDialogs
  Gui, Show, NA
  
  hwnd:= WinExist()
  hbm := CreateDIBSection(mwW:=87, mwH:=49)
  hdc := CreateCompatibleDC()
  obm := SelectObject(hdc, hbm)
  G   := Gdip_GraphicsFromHDC(hdc)
  
  Gdip_SetSmoothingMode(G, 4)
  MouseGetPos, mX, mY
  UpdateLayeredWindow(hwnd, hdc, mX, mY, mwW, mwH)
  OnMessage(0x200, "WM_MOUSEMOVE")
  SetTimer, mainWindowContent, 200
  
mainWindowContent:
  SetTimer, mainWindowContent, Off
  IF !GUI_ACTIVE
  return
  Gdip_SetCompositingMode(G, 1) ; set to overdraw
  pBrush := Gdip_BrushCreateSolid(0x00000000) ; fully transparent brush 'eraser'
  Gdip_FillRoundedRectangle(G, pBrush, 0, 0, mwW, mwH, 10)
  Gdip_DeleteBrush(pBrush)
  Gdip_SetCompositingMode(G, 0) ; switch off overdraw
  
  MouseGetPos, mX, mY
  pBitmap:= Gdip_BitmapFromScreen(mX "|" mY "|1|1")
  color  := Gdip_GetPixel(pBitmap, 0, 0) & 0xFFFFFF
  tcolor := (color > 0x800000)? "ff000000": "ffFFFFFF"
  
  pBrush := Gdip_BrushCreateSolid(0x7FC0C0C0)
  Gdip_FillRoundedRectangle(G, pBrush,   0,   0, mwW,  mwH, 10)
  Gdip_DeleteBrush(pBrush)
  pBrush := Gdip_BrushCreateSolid(0xFF000000+color)
  Gdip_FillRoundedRectangle(G, pBrush,  10,  10, mwW-20, mwH-20, 5)
  Gdip_DeleteBrush(pBrush)
  Gdip_TextToGraphics(G, format("{1:4d}:{2:4d}", mX, mY), "X0 Y13 Center C" tcolor " R4 S10 Bold", "Verdana", mwW, 47)
  Gdip_TextToGraphics(G, format("{1:06X}", color)       , "X0 Y25 Center C" tcolor " R4 S10 Bold", "Verdana", mwW, 47)
  UpdateLayeredWindow(hwnd, hdc)
  SetTimer, mainWindowContent, On
return

WM_MOUSEMOVE()
{ PostMessage, 0xA1, 2
}

!Space:: IF GUI_ACTIVE:=!GUI_ACTIVE, SetTimer, mainWindowContent, On ;Alt+Space freeze
#Space::Gui,% ((HideShow := !HideShow)? "Hide":"Show") ;Win+Space Show/Hide
#!F4::ExitApp ;Win+Alt+F4 exit
Script void funny small semi transparent window with x:y global mouse position and RGB color at the position. Script not use PixelGetColor and "see" all colors that are visible ignoring A color attribute.

Code: Select all

#SingleInstance, Force
CoordMode, Mouse, Screen

  pToken:= Gdip_Startup()
  Gui, -Caption +E0x80000 +LastFound +AlwaysOnTop +ToolWindow +OwnDialogs
  Gui, Show, NA
  
  hwnd:= WinExist()
  hbm := CreateDIBSection(mwW:=87, mwH:=49)
  hdc := CreateCompatibleDC()
  obm := SelectObject(hdc, hbm)
  G   := Gdip_GraphicsFromHDC(hdc)
  
  Gdip_SetSmoothingMode(G, 4)
  MouseGetPos, mX, mY
  pBrush := Gdip_BrushCreateSolid(0x7FC0C0C0)
  Gdip_FillRoundedRectangle(G, pBrush,   0,   0, mwW,  mwH, 10), Gdip_DeleteBrush(pBrush)
  UpdateLayeredWindow(hwnd, hdc, mX, mY, mwW, mwH)
  OnMessage(0x200, "WM_MOUSEMOVE")
  ShowHide:= RunStop:= 1
  SetTimer, mainWindowContent, 100
  
mainWindowContent:
  MouseGetPos, mX, mY
  color  := Gdip_GetPixel(Gdip_BitmapFromScreen(mX "|" mY "|1|1"), 0, 0) & 0xFFFFFF
  tcolor := (color > 0x800000)? "ff000000": "ffFFFFFF"
  
  pBrush := Gdip_BrushCreateSolid(0xFF000000|color)
  Gdip_FillRoundedRectangle(G, pBrush,  10,  10, mwW-20, mwH-20, 5), Gdip_DeleteBrush(pBrush)
  Gdip_TextToGraphics(G, format("{1:4d}:{2:4d}", mX, mY), "X0 Y13 Center C" tcolor " R4 S10 Bold", "Verdana", mwW, 47)
  Gdip_TextToGraphics(G, format("{1:06X}", color)       , "X0 Y25 Center C" tcolor " R4 S10 Bold", "Verdana", mwW, 47)
  UpdateLayeredWindow(hwnd, hdc)
return

!Space::RunStop :=!RunStop , GuiControl()
#Space::ShowHide:=!ShowHide, GuiControl()
#!F4::ExitApp
WM_MOUSEMOVE()
{ PostMessage, 0xA1, 2
}
GuiControl()
{ global
  if ShowHide
  { if RunStop, SetTimer, mainWindowContent, On
    else      , SetTimer, mainWindowContent, Off
    Gui, Show
  } else
  { SetTimer, mainWindowContent, Off
    Gui, Hide
} }
Less code same result.
Optimized drawing and CPU usage. There some color glitches due to trigonometrical rounding of angles.
Last edited by _3D_ on 09 May 2015, 00:19, edited 2 times in total.
AHKv2.0 alpha forever.
_3D_
Posts: 277
Joined: 29 Jan 2014, 14:40

InGame v2.0 SOME REMARKS

03 Mar 2014, 17:48

1.SendMode
AHK_L Event: This is the starting default used by all scripts.
AHKv2.0 Input: This is the starting default used by all scripts.

Converting scripts from AHK_L to AHKv2.0 need SendMode Event else SetKeyDelay not worked.
It is important in game.

2.USE only 1 convention for commands and arguments
I think I will use only function convention - this way arguments always known what type is.
command(arg, arg, arg)
function(arg, arg, arg)
"string"

3.DllCall(..., "Cdecl [TYPE]")
IF DllCall not work or AHK v2.0 void strange messages that mention Cdecl
[Solution]
1. if function return value DllCall(... , "Cdecl [Type]") - add "Cdecl VALUEtype" like last extra argument
2. if function not return value DllCall(... , "Cdecl") - add just "Cdecl" like last extra argument
AHKv2.0 alpha forever.
_3D_
Posts: 277
Joined: 29 Jan 2014, 14:40

InGame v2.0 my little OCR

11 Mar 2014, 18:08

Games are fun and of course auctions in games are funniest :P
Now my little experience in fast buying.
What is OCR?
Optical Character Recognition or how to teach the computer to read.
Let first said that "computer" will read only digits 0..9 decimal notation. The digits (in my case) are equal sized and with equal spacing (gap between symbols).
Patterns
Digit : width= 5 x height= 7
gap : width= 1 x height= 7
coma: width= 1 x height= 7
Due to all digits equal I made small bitmaps with all 10 digits 0..9.
AHKv2.0

Code: Select all

ocrBWConvert(ByRef bmp, color, varia:=0) ;convert bmp pattern to Black / White pattern 
{ Gdip_GetImageDimensions(bmp, w, h)
  Loop h 
  { y:=A_Index-1
    Loop w
    { x:= A_Index-1
      Gdip_SetPixel(bmp, x, y, PixelCompare(Gdip_GetPixel(bmp, x, y), color, varia)? 0xFFFFFFFF: 0xFF000000)
  } }
  return bmp 
} ;===============================================
The code convert bmp pattern to black foreground with white symbol in next order:
1.Get pixel from bitmap
2.Compare pixel to given color with given variation
3.If pixel match pixel is set to white
4.Else pixel is set to black
AHKv2.0

Code: Select all

PixelCompare(ARGB1, ARGB2, varia:=0) ;compare ARGB1 to ARGB2 with variation (0..255)
{ Gdip_FromARGB(ARGB1, A1, R1, G1, B1)
  Gdip_FromARGB(ARGB2, A2, R2, G2, B2)
  return (abs(R1-R2) <= varia) && (abs(G1-G2) <= varia) && (abs(B1-B2) <= varia)
} ;===============================================
A color attribute is ignored. 0= strong equal. 255= any match.
Now I have 0.bmp .. 9.bmp patters and ready to read and compare.

Code: Select all

;try to recognize recBmp pattern compare to 0..9 given patterns 
ocrGetDigit(recBmp, color, varia)
{ static digBmp:= object(0,"", 1,"", 2,"", 3,"", 4,"", 5,"", 6,"", 7,"", 8,"", 9,"")
  static digIni ;static init bmps from file not work
  if !digIni     ;load bmps once till script exit
  { Loop 10
      digBmp[A_Index-1]:= Gdip_CreateBitmapFromFile(A_ScriptDir "\ocr\" A_Index-1 ".bmp")
    digIni:=1  
  }    
  Loop 10
    if ocrBWCompare(recBmp, digBmp[A_Index-1], color, varia), return A_Index-1
  return "" ;fail
} ;===============================================
function return 0..9 or "" if nothing is recognized.
If we search white digit: ocrGetDigit(bmpFromScreen, 0xFFFFFF, 50) ;50 is good variation
If we search red digit: ocrGetDigit(bmpFromScreen, 0xFF0000, 50)
If we search blue digit: ocrGetDigit(bmpFromScreen, 0x0000FF, 50)

And comparison - it is complicated but idea is the same like conversion If color match WHITE else BLACK.
AHKv2.0

Code: Select all

ocrBWCompare(recog, given, color, varia:=0) ;compare bmp patterns reduce collors to Black / White
{ Gdip_GetImageDimensions(given, w, h) 
  Loop h 
  { y:= A_Index-1
    Loop w
    { x:= A_Index-1
      if (Gdip_GetPixel(given, x, y) & 0xFFFFFF) != (PixelCompare(Gdip_GetPixel(recog, x, y), color, varia)? 0xFFFFFF: 0x000000)
        return 0 ;fail  
  } }
  return 1 ;success
} ;===============================================
At the end as the pattern is BLACK/WHITE and if color match/not match it is like comparing binary patterns (1=WHITE/0=BLACK) and in the same time quiet clean to be seen.

Further I will post how to concatenate recognized digits to value.
AHKv2.0 alpha forever.
_3D_
Posts: 277
Joined: 29 Jan 2014, 14:40

InGame v2.0 my little OCR - from digit to volume

12 Mar 2014, 18:20

Now we have method to get single digit let make it difficult.

Code: Select all

1,234,567,890 
[symbol]gap[symbol]
 1   ,   2   3   4   ,   5   6   7   ,   8   9   0
[5]1[2]1[5]1[5]1[5]1[2]1[5]1[5]1[5]1[2]1[5]1[5]1[5]
Let get this long (long int) line and convert it value.
I chose method LEFT TO RIGHT because there some trick that help me to check if recognition is complete.
The trick: Ill count how many "miss" will generate algorithm while going recognition and at the end Ill compare with the lenght of the value represent like string.

Code: Select all

val:=1000000000, buyItemPrice:= 0
      mis:=10 
      loop 10
      { bmp:= Gdip_BitmapFromScreen(mX "|" mY "|5|7") ;get pattern 
        d:= ocrGetDigit(bmp, 0xFFFF00, 50)            ;recognize YELOW digit
        Gdip_DisposeImage(bmp)
        if d != "", buyItemPrice += d*val             ;value := digit * order
        else mis--                                    ;else count miss
        val //= 10                                    ;integer division
        mX += (mod(A_Index, 3) == 1)? 9: 6            ;if "," +9 else +6  
      }
      len:= StrLen(buyItemPrice)
Here we have like result: buyItemPrice, len of buyItemPrice and mis.
As we start left to right any time if partial recognition we have great value instead right to left recognition. If right to left we don`t know is there really NO digit or partial recognition. My experience void next examples:

Code: Select all

1,234,567,890 - left to right                   | right to left
        1,234 - value==    1234 mis== 4 len== 4 | value==    1234 mis== 6 len== 4
    1,234,567 - value== 1234567 mis== 7 len== 7 | value== 1234567 mis== 3 len== 7
If COMPLETE recognition there no any matter left to right or right to left will be the recognition. BUT if PARTIAL recognition (lag, some notes appeared, etc. over the patterns left to right will return great value (left most digits) but right to left will return low value (right most)). As we need low value (it is game "money") like price I chose left to right.

Code: Select all

x xxx x67,890 - right to left =      67890 mis== 5 len== 5 - low price recognized
1,234,567,890 - real            1234567890 mis==10 len==10 - real           
1 2xx xxx xxx - left to right = 1200000000 mis== 2 len==10 - high price recognized
If USER will buy at 500,000 left to right will return WAIT but right to left will return BUY.

Code: Select all

If (len == mis) && (buyItemPrice <= buyUserPrice), " <<< BUY >>> "
I like this miss/length trick.
AHKv2.0 alpha forever.
_3D_
Posts: 277
Joined: 29 Jan 2014, 14:40

InGame v2.0 Forced Type conversion

18 Mar 2014, 06:12

AHKv2.0
I have some troubles with data type stored in variables and made 3 simple functions that forced conversion of data type.
Type to String:

Code: Select all

__str(ByRef arg) ;forced conversion to string 
{ return arg .= ""
} ;===============================================
Just adding empty string.

Type to Float:

Code: Select all

__flo(ByRef arg, defaultValue:=.0) ;forced conversion to float
{ return (Type(arg + .0) == "Float"? arg += .0: arg:= defaultValue + .0)
} ;===============================================
The same adding 0.0 float format. If default value is Integer defaultValue + .0 convert it to float.

Type to Integer:

Code: Select all

__int(ByRef arg, defaultValue:=0) ;forced conversion to integer
{ try
  { Goto % "__int_" Type(arg + 0) ;switch
__int_Integer:                     ;case Integer
    return arg += 0
__int_Float:                       ;case Float
    return (arg:= round(arg))
  }
  catch                           ;default  
    return arg:= defaultValue ;if defaultValue Float or String you will get the same type.
} ;===============================================
Again adding 0 integer type.

Both functions __int() and __flo() have defaultValue if input data cant be converted to value.

Code: Select all

Expresion: Type(arg + 0) return Integer/Float only if argument may be converted to value.
Type("10" + 0) => Integer and function return (integer)10
Type("h0" + 0) => String  and function return (integer)defaultValue

Code: Select all

Expresion: Type(arg + .0) return Float only if argument may be converted to value.
Type("10"   + .0) => Float  and function return (float)10
Type("10.1" + .0) => Float  and function return (float)10
Type("h0"   + .0) => String and function return (float)defaultValue
AHKv2.0 alpha forever.
_3D_
Posts: 277
Joined: 29 Jan 2014, 14:40

InGame v2.0 Switch() - conceptual model

19 Mar 2014, 14:32

Inspired from __int() function attempt to realize Switch.
AHKv2.0

Code: Select all

switch(arg)              ;encapsulate labels
{ try                    ;realize "default"
  { loop 1               ;realize "break" 
    { goto % "CASE_" arg ;switch(arg)
      CASE_1:             ;case 1: (local label)
      { MsgBox("1=" arg)
        break            ;goto after loop
      } 
      CASE_2:             ;case 2:
      { MsgBox("2=" arg)
      }                  ;continue to CASE_3
      CASE_3:             ;case 3:
      { MsgBox("3=" arg)
        throw            ;allow goto default <extra>
      }
      CASE_4:             ;case 4:
      { MsgBox("4=" arg)
        return           ;exit function
    } } ; end loop ===============================
    ;after loop <extra>
  } ;end try =====================================
  catch                  ;default:
  { MsgBox("D=" arg)
  } ;end catch ===================================
  ;after try \ finally    
} ;end switch ====================================
Known Limitations:
1. Due to any Switch must be function (to encapsulate labels and to avoid label duplications) using 2 or more Switches in common scope void problems with common used variables (any Switch work with self variable scope).
Using global not so good if your code function oriented.
2. Due to labels are case insensitive switch is case insensitive too.

Known Extras:
1. Break - break loop block not whole switch
2. Throw - any case statement can continue to default
3. Return - break function
4. Continue - when loop, Parse \ loop, Read

This way we have 3 default statements:
1. after loop - for any "recognized" cases
2. catch - default for "UNrecognized" cases
3. after try (you may use finally the result is the same).

Conclusion:
Switch function have 4 logically separated sections
1. try inside loop
2. try after loop
3. catch {...}
4. after try \ finally {...}
If need to represent Switch\Case statement use any section ONCE and in rising order.
First time I like GOTO :P

Funny Switch example with continue <extra>.
AHKv2.0

Code: Select all

switchParse("RED YELLOW GREEN YELLOW")
switchParse(arg, time:= 3)
{ loop time
  { try
    { loop, parse,% arg,% " "
      { goto % "CASE_" A_LoopField
        CASE_RED:
           ToolTip("STOP")
          Sleep(2000)
          continue
        CASE_YELLOW:
           ToolTip("DO NOT CROSS")
          Sleep(1000)
          continue
        CASE_GREEN:
           ToolTip("GO")
          Sleep(2000)
      }
      throw
    }
    catch
      ToolTip("LIGHTS OFF")
} }
#!F4::ExitApp
Lights run 3 times and "unfortunately throw an exception" :roll: :roll: :roll:
Last edited by _3D_ on 20 Mar 2014, 01:24, edited 1 time in total.
AHKv2.0 alpha forever.
_3D_
Posts: 277
Joined: 29 Jan 2014, 14:40

InGame v2.0 - Advanced Beep()

24 Mar 2014, 05:05

Inspired jNizM https://github.com/jNizM/AHK_DllCall_Wi ... s/Beep.ahk
Advanced Beep no wait after last beep
AHKv2.0

Code: Select all

beep(5, 500, 100, 100) ;usage
beep(loop:= 1, freq:= 770, dura:= 200, wait:= 200)
{ while loop--           ;if loop == 1 dont wait
  { DllCall("Kernel32.dll\Beep", "UInt", freq, "UInt", dura)
    if loop, Sleep(wait) ;dont wait after last beep
} } ;=============================================
And another Advanced Beep version
AHKv2.0

Code: Select all

loop 5
{ beep(5, 500, 100, 20) ;usage
  beep(2, 600, 100, 20) ;usage
}  
beep(loop:= 1, freq:= 770, dura:= 200, wait:= 200)
{ loop loop              ;loop loop times :P
  { DllCall("Kernel32.dll\Beep", "UInt", freq, "UInt", dura)
    if wait, Sleep(wait) ;if wait == 0 dont wait
} } ;=============================================
Funny small function thanks jNizM.
AHKv2.0 alpha forever.
_3D_
Posts: 277
Joined: 29 Jan 2014, 14:40

InGame v2.0 Ticker

30 Mar 2014, 18:36

Actually this is the reason to use and learn AutoHotkey.
It is a script that control remote computer that run some actions in given interval of time.
Today I remake it to v2.0 and do "small" demo example.
AHKv2.0

Code: Select all

#SingleInstance force
;Copyright (c) D.Donchev

SendMode , Event
CoordMode, Mouse, Screen
CoordMode, Pixel, Screen
SetTitleMatchMode, 2
; PRE ACTION =====================================
waitTimer:= workTimer:= 0 
; GUI INIT =======================================
    pToken:= Gdip_Startup()
    Gui, 1: -Caption +E0x80000 +LastFound +AlwaysOnTop +ToolWindow +OwnDialogs
    Gui, 1: Show, NA
    hwnd1 := WinExist()
    hbm   := CreateDIBSection(mw_w:=250, mw_h:=52)
    hdc   := CreateCompatibleDC()
    obm   := SelectObject(hdc, hbm)
    G     := Gdip_GraphicsFromHDC(hdc)
; MAIN WINDOW ====================================
    Gdip_SetSmoothingMode(G, 4)
    Gdip_FillRoundedRectangle(G, pBrush:=Gdip_BrushCreateSolid(0x7FC0C0C0),  0,  0, 250, 52, 8)
    Gdip_DeleteBrush(pBrush)
    Gdip_FillRoundedRectangle(G, pBrush:=Gdip_BrushCreateSolid(0xFF302226), 10, 10, 230, 32, 4)
    Gdip_DeleteBrush(pBrush)
    UpdateLayeredWindow(hwnd1, hdc, 15, 15, mw_w, mw_h), OnMessage(0x200, "WM_MOUSEMOVE")
mainWindowContent(1000) ;BEGIN of time =========== start ticker
; ACTION =========================================
try
{        myToolTip("POWER ON")
         mySleep(5)
         acctCount:= 1, acctUser:= "150:150"
         myToolTip("150:150")
         UpdateLayeredWindow(hwnd1, hdc, 150, 150)
         Sleep(5000) ;mySleep(5)
         acctCount:= 2, acctUser:= "NO TIP"
         myToolTip()
         mySleep(5)
         myToolTip("MOVE")
         acctUser:= ">>>"
         loop 5
         { acctCount++
           UpdateLayeredWindow(hwnd1, hdc, 150 + A_Index*20, 150)
           mySleep(1, 10-A_Index)
         }
         acctUser:= ""
         ;throw ;emergency stop the ACTION
         myToolTip("END")
         mySleep(5)
         myToolTip() 
} catch { 
} ;nothing to catch - emergency stop the ACTION        
; ACTION END =====================================  
CloseAndWait:
         nextTime := 40                       ;wait init
         waitTimer:= nextTime - workTimer - 2 ;wait correction
; WAITIING <<< script main action stop here >>>
#!Q::ExitApp                          ;#Persistent
; FUNCTIONS ######################################
__hms(arg)
{ ss:= mod(arg, 60), arg //=60
  return format("{1:02d}:{2:02d}:{3:02d}", arg // 60, mod(arg, 60), ss)
} ;===============================================
myToolTip(_i:="", _x:="")
{ static tip, txt
  if !(txt:= _x), tip:= _i
  ToolTip(txt (txt && tip? " ": "") tip)
} ;===============================================
mySleep(tm, tt:="")
{ while tm
  { myToolTip(, format("{1:02d}", (tt? tt:tm)))
    tm--
    Sleep(1000)
} } ;=============================================
mainWindowContent(tm) ;MAIN TICKER
{ global
  SetTimer, LBmainWindowContent,% tm
LBmainWindowContent: ;BODY =======================
  SetTimer, LBmainWindowContent, Off
  Gdip_FillRoundedRectangle(G, pBrush:=Gdip_BrushCreateSolid(0xFF302226),  10,  10, 230, 32, 4)
  Gdip_DeleteBrush(pBrush)
  Gdip_TextToGraphics(G, FormatTime("T12", "dd.MM.yy dddd hh:mm:ss"), "x10 y10 Center cFFFDD017 r4 s11", "Verdana", 230, 47)
  
  if waitTimer > 0
  { progressBarText:= __hms(--waitTimer)
    progressBarLine:= waitTimer/nextTime
    exitCode:= !waitTimer
  } 
  else
  { progressBarText:= "[" acctCount "] " acctUser " [" format("{1:02d}:{2:02d}", workTimer // 60, mod(workTimer, 60)) "]"
    workTimer++
    progressBarLine:= 0
  }
  Gdip_FillRoundedRectangle(G, pBrush:=Gdip_BrushCreateSolid(0xFF300000), 13, 25, 224, 14, 2)
  Gdip_DeleteBrush(pBrush)
  Gdip_DrawLine(G, pPen:=Gdip_CreatePen(0xFF663311, 11), 15, 32, 15+220*progressBarLine, 32)
  Gdip_DeletePen(pPen)
  Gdip_TextToGraphics(G, progressBarText, "x" 13 " y" 24 " Center cFFFDD017 r4 s" 12 " Bold", "Verdana", 224, 47)
  
  UpdateLayeredWindow(hwnd1, hdc)
  if !exitCode, SetTimer, LBmainWindowContent, On
  else Reload ;Run, shutdown -r -t 01
RETURN ;BODY ===================================== 
} ;=============================================== 
WM_MOUSEMOVE()
{ PostMessage, 0xA1, 2
} ;===============================================
Unzip Gdip.ahk to Lib folder. (Gdip.ahk AHKv2.0_"Ptr" version tested only at x86).
Script will reload any 40 sec and do some funny things and show some messages and ToolTips.
You can edit / remake / change the time intervals till the script is in action and in next reload newly made changes will take effect (don`t forget to save script).
Attachments
Gdip.zip
(19.03 KiB) Downloaded 502 times
AHKv2.0 alpha forever.
_3D_
Posts: 277
Joined: 29 Jan 2014, 14:40

InGame v2.0 Remapping Fn Key or T41 (T$)T&$T$@...)

01 Apr 2014, 13:42

T$)T$!T$@ == T40T41T42 :lol:

I got an old IBM ThinkPad T41 and of course FIRST thing was to remap Fn and Ctrl (no in BIOS sollution).
For these that don`t know what I said: T41 NO WIN button and leftmost down button is Fn then Ctrl and Alt in right.
It is strange "solution" from IBM but they solved in newer models.

NOW Trust me I read all AHK forums and other "laity" posts including IBM and Microsoft coryphaeus and conclusions:

AHK and Windows remap Fn key but actually due to hardware dependence have some side effects:
1. Single pressing Fn run like single pressed Win (cool).
2. Fn and other key (for example R) don`t appear run and instead work like permanent WIN down :P

Some particulars:
Scan code:
0xE063 <<< hardware style
SC163:: <<< AHK / Win style

Whole day I remap / read / remap /read and the sollution:
I remap Capslock to Win , keep Fn Ctrl Alt order at last keyboard line. :P
http://www.howtogeek.com/howto/windows- ... ows-vista/ best explanation.
And best way to remap edit registry or KeyTweak http://www.softpedia.com/get/System/OS- ... weak.shtml sorry no home page :(

Sorry no source code but not needed :P HAK YAK AHK :P
(Edit)
Why Fn CANT be mapped to Win, Ctrl or Alt >>>
using this GREAT script by SKAN http://www.autohotkey.com/board/topic/2 ... -of-a-key/ I explore the how Fn button work.
1. Pressing Fn - nothing happen (unlike other modifier buttons (first problem))
2. After a while (time for autorepeat) keyboard return 0x0163
3. After a while (time for autorepeat) keyboard repeat return 0x4163 (0x4xxx mean repeat flag (button hold))
4. When release keyboard return 0xC163 (0xCxxx mean release flag (button up))

Except 2. Fn void like normal modifier key (Ctrl, Win, Alt, Shift).
NOW where is the problem?
When Pressed Fn button prevent other buttons to return there scan codes :( :( :( this "simple" detail is the reason to be unable to do replacement :( :( :( that mean Fn+<other key> is the same like just Fn :( :( :(
AHKv2.0 alpha forever.
_3D_
Posts: 277
Joined: 29 Jan 2014, 14:40

[FUNCTION] IsFileModified()

23 Apr 2014, 05:21

When in test mode or remote mode running script need to be Reloaded time to time when the source of the script changed.
Next small function can be used to determinate is script modified by previous check and force reload.

Code: Select all

;init time stamp
IsFileModified("A_ScriptModified") ;first call
;create time stamp variable (global) 

msgBox("Modify the script to Reload [" A_ScriptModified "]")

;compare time stamp
if IsFileModified("A_ScriptModified"), Reload ;second call

;function compare previous and current file modification time stamp
;md:= file time stamp variable name for the given file 
;fn:= file name (if omitted fn is script full path name)
;
;return time stamp (file     modified)
;return 0          (file NOT modified)
IsFileModified(md, fn:="") ;compare Modified file time stamp
{ global
  if (fn:= fileGetTime(fn? fn: A_ScriptFullPath)) != %md%, return %md%:=fn ;modified
  ;create (global) variable %md% and set current time stamp
  return 0 ;NOT modified keep previous time stamp
} ;===============================================

This way If file (script) modified till running we can check and reload the new content in appropriate moment. The variable is translated byName to avoid mistakes inside other functions and needs of word global.
AHKv2.0 alpha forever.
_3D_
Posts: 277
Joined: 29 Jan 2014, 14:40

PixelGetColor

04 May 2014, 07:45

As I see there are omission in DD_GetPixel that I post early and it cant "see" any colors.
The Fix + Add
AHKv2.0

Code: Select all

#SingleInstance, Force
CoordMode, Mouse, Screen

  pToken:= Gdip_Startup()
  Gui, -Caption +E0x80000 +LastFound +AlwaysOnTop +ToolWindow +OwnDialogs
  Gui, Show, NA
  
  hwnd:= WinExist()
  hbm := CreateDIBSection(mwW:=87, mwH:=49)
  hdc := CreateCompatibleDC()
  obm := SelectObject(hdc, hbm)
  G   := Gdip_GraphicsFromHDC(hdc)
  
  Gdip_SetSmoothingMode(G, 4)
  MouseGetPos, mX, mY
  pBrush := Gdip_BrushCreateSolid(0x7FC0C0C0)
	Gdip_FillRoundedRectangle(G, pBrush,   0,   0, mwW,  mwH, 10), Gdip_DeleteBrush(pBrush)
	UpdateLayeredWindow(hwnd, hdc, mX, mY, mwW, mwH)
  OnMessage(0x200, "WM_MOUSEMOVE")
  ShowHide:= RunStop:= 1
  SetTimer, mainWindowContent, 100
  
mainWindowContent:
  MouseGetPos, mX, mY                                            ; vvv    raster Fix   vvv
  color  := Gdip_GetPixel(Gdip_BitmapFromScreen(mX "|" mY "|1|1", 0x40000000 | 0x00CC0020), 0, 0) & 0xFFFFFF
  tcolor := (color > 0x800000)? "ff000000": "ffFFFFFF"
  
  pBrush := Gdip_BrushCreateSolid(0xFF000000|color)
	Gdip_FillRoundedRectangle(G, pBrush,  10,  10, mwW-20, mwH-20, 5), Gdip_DeleteBrush(pBrush)
  Gdip_TextToGraphics(G, format("{1:4d}:{2:4d}", mX, mY), "X0 Y13 Center C" tcolor " R4 S10 Bold", "Verdana", mwW, 47)
  Gdip_TextToGraphics(G, format("{1:06X}", color)       , "X0 Y25 Center C" tcolor " R4 S10 Bold", "Verdana", mwW, 47)
  UpdateLayeredWindow(hwnd, hdc)
return

!Space::RunStop :=!RunStop , GuiControl()
#Space::ShowHide:=!ShowHide, GuiControl()
#P:: ;move mouse pointer to possition
  m:= StrSplit(InputBox("Position(X Y)",,"W150 H100",mX " " mY), array(" ", ":", "|"))
  MouseMove(m[1], m[2])            
return
#!F4::ExitApp
WM_MOUSEMOVE()
{ PostMessage, 0xA1, 2
}
GuiControl()
{ global
  if ShowHide
  { if RunStop, SetTimer, mainWindowContent, On
    else      , SetTimer, mainWindowContent, Off
    Gui, Show
  } else
  { SetTimer, mainWindowContent, Off
    Gui, Hide
} }
There added forced mouse pointer movement to absolute position

Code: Select all

#P:: ;move mouse pointer to possition
  m:= StrSplit(InputBox("Position(X Y)",,"W150 H100",mX " " mY), array(" ", ":", "|"))
  MouseMove(m[1], m[2])            
return
Possible syntax:
"X Y" - space separator
"X:Y" - semicolon separator
"X|Y" - | separator
AHKv2.0 alpha forever.
_3D_
Posts: 277
Joined: 29 Jan 2014, 14:40

Re: InGame v2.0

17 Jun 2014, 15:59

2014 Brazil script

The name of the game ?
Football.

Code: Select all

loop 
{ Get Beer
  loop 2
  { Sing, The name of the game ?
    Sing, Football.
  }
  loop 2
  { Sing, Oleee, Oleee, Oleee, Oleee.
    Sing, We are the champs. We are the cmapions.
} }
Enjoy.
AHKv2.0 alpha forever.
_3D_
Posts: 277
Joined: 29 Jan 2014, 14:40

WM_FUNCTIONS Arguments

08 Sep 2014, 14:53

SmallFuncion xyArg() for OnMessage:

Code: Select all

OnMessage(0x200, "WM_MOUSEMOVE" )

WM_MOUSEMOVE(wp, y, ms, hd)  ;second argument is wordY:wordX
{ xyArg(x, y)
  ToolTip(x ":" y)
  PostMessage, 0xA1, 2
} ;===============================================
xyArg(ByRef x, ByRef y) ;function separate Hi:Lo word of y to x:y
{ x:=mod(y, 65536), y//=65536 
} ;=============================================== smallFunctions - event
This way xyArg(x, y) simply will return x and y coordinates of mouse pointer related to GUI of WM_MOUSEMOVE caller in "window mode" no mater what CoordMode, Mouse is set.
AHKv2.0 alpha forever.
_3D_
Posts: 277
Joined: 29 Jan 2014, 14:40

Re: Simple WATCH DOG

04 Oct 2014, 04:31

This days I revised a script that play like a bot with a browser game (html and flash mixture).
There was a strange problem (time to time) flash player freeze and in result browser freezes too.
I have a strange feeling that Firefox not manage plugins correctly and change browser to Opera.
And freezings low down in times but still appears. Because this freezings appeared in unknown order I write a small WATCH DOG.

Code: Select all

watchDOG() ;usage
watchDOG(t:=1000)
{ SetTimer, LB_watchDOG, %t% ;start watch dog timer
LB_watchDOG:
  SetTimer, LB_watchDOG, Off ;stop watch dog timer
  DetectHiddenWindows, On    ;allow detecting of hiden windows
  if WinExist("Adobe")       ;find Adobe Crash reporter
  { WinKill                  ;kill Adobe
    WinActivate("Opera")     ;focus back to browser
    Send("{F5}")             ;reload current page in browser and start Flash player 
  }
  SetTimer, LB_watchDOG, On  ;start watch dog again
RETURN
}
ENJOY!
AHKv2.0 alpha forever.

Return to “Gaming”

Who is online

Users browsing this forum: No registered users and 5 guests