[v2 Showcase] Script displaying some of AHKv2's usage and syntax

Post your working scripts, libraries and tools.
User avatar
kczx3
Posts: 1649
Joined: 06 Oct 2015, 21:39

[v2 Showcase] Script displaying some of AHKv2's usage and syntax

Post by kczx3 » 30 Mar 2018, 07:24

I got a little excited with the latest changes in the V2 alpha so I decided to finally take the plunge and convert one of my scripts to use it. Even without the latest changes, I really am wishing that I would have switched to using it sooner. The GUI object model is sooooooo much nicer to work with. Being able to get a GUI object (or gui control object) from its hwnd is a great feature. The _NewEnum method of the GUI Object is awesome and has the added bonus that it loops over controls in the order they were added to the GUI.

NOTES:
  • Requires v2.0-a090-ae96c4a or above.
  • Uses JSON lib by Coco - Implementation on GitHub didn't support AHK v2 so I am including my slightly modified version below as well.
I think one of the largest hurdles to gaining v2 adoption is the lack of code/libraries out there using it. Its very hard to switch when all the great code is mostly in v1.1. So while the purpose of this script will not have any value for others, I do think it can serve as a starting point for others to understanding the syntax and capabilities. Enjoy and please feel free to critique.

EDIT: Code updated to handle WM_MOUSEWHEEL messages instead of using Hotkeys to avoid MaxHotkeysPerInterval issue.

Code: Select all

;===========================================================================================
; This script is used to populate a form with values.  The form is part of an application that
; is delivered by Citrix and therefore keystrokes are all we can do to populate the fields
; Using the fields1 and fields2 objects, a GUI is populated to look exactly like the form.
; Each field has a default value but has an associated UpDown control for users to change them.
;
; Usage: Open the script, pick which form you are filling out, then click the Insert Data
;        button to send the data.  It will then wait for the user to hit the Enter key before
;        sending the data.  For testing, simply open Notepad then switch to this tool and 
;        click the Insert Data button.
;===========================================================================================
#Include <JSON>
#SingleInstance Force

guiW := 700
guiH := 400
scrollW := SysGet(2)

data := JSON.Load(FileRead("AutoLabs.json"))

;**************************************************************************************************
; Main GUI
;**************************************************************************************************
mainGui := GuiCreate("+Resize", windowTitle)
mainGui.BackColor := "White"
mainGui.MarginX := mainGui.MarginY := 10
mainGui.OnEvent("Close", () => ExitApp())
mainGui.OnEvent("Size", "MainSize")

mainGui.Add("Button", "h30 Default Section", "Insert Data").OnEvent("Click", "InsertData")
mainGui.Add("Text", "ys x+50 Section", "PowerForm Selection:")
mainGui.Add("DropDownList", "xs yp+15 w175 r5 AltSubmit vForm", "Labs Cerner Test Use Only||Cerner Education Use Only").OnEvent("Change", "DDL")
mainGui.Add("Text", "ys-5 x+120", "Log into PowerChart and`nopen the form before`nclicking 'Insert Data'")
mainGui.Add("Text", "ys-5 w1 h40 0x11")
mainGui.Add("Text", "ys-5", "Use the arrow buttons or`nhold Alt and scroll`nto change the values.")

;**************************************************************************************************
; Labs Cerner Test Use Only
;**************************************************************************************************
labsGui := GuiCreate("0x200000 +ToolWindow -Caption -SysMenu +Parent" mainGui.hwnd, "")
labsGui.MarginX := labsGui.MarginY := 10
labsGui.OnEvent("Size", (gObj, minMax, w, h) => UpdateScrollBars(gObj.hwnd, w, h))

labsGui.Add("Checkbox", "Checked0 Section vincludeIcu", "Include ICU Labs?")

; Add controls from first object
newSection := 0
for i, item in data.fields1 {
    newSection++
    if (item.name = "_DIVIDER") {
        labsGui.Add("Text", "xs y+m h20 w" guiW - scrollW - 20 " 0x200 Background3198FF Center Section", item.text).SetFont("bold")
        newSection := 0
    }
    else {
        ; Make a new row ever 2 "controls"
        if (mod(newSection, 2) = 1) {
            opts := "xs w125 Section"
        }
        ; Otherwise the next is in a new column
        else {
            opts := "ys w125"
        }
        labsGui.Add("Text", opts, item.name)
        labsGui.Add("Edit", "ys-3 w75 Limit ReadOnly", item.default)
        ; Note: The "-2" option is recommended when creating non-unitary UpDown controls, because
        ; it prevents a glitch that may otherwise occur when the control is greatly solicited
        ; (e.g. when using the mouse wheel to scroll the value).
        ; It disables the control's UDS_SETBUDDYINT style flag.
        labsGui.Add("UpDown", "-2")
        labsGui.Add("Text", "ys w100", item.refRange " " item.units)
    }
}
labsGui.Show("x0 y50 h" guiH - 50 " w" guiW - scrollW)

;**************************************************************************************************
; Cerner Education Use Only form
;**************************************************************************************************
eduGui := GuiCreate("0x200000 +ToolWindow -Caption -SysMenu +Parent" mainGui.hwnd, "")
eduGui.MarginX := eduGui.MarginY := 10
eduGui.OnEvent("Size", (gObj, minMax, w, h) => UpdateScrollBars(gObj.hwnd, w, h))

; Add controls from first object
newSection := 0
for i, item in data.fields2 {
    newSection++
    if (item.name = "_DIVIDER") {
        eduGui.Add("Text", "xs y+m h20 w" guiW - scrollW - 20 " 0x200 Background3198FF Center Section", item.text).SetFont("bold")
        newSection := 0
    }
    else {
        ; This doesn't need xs since it is the first control on this GUI
        if (i = 1) {
            opts := "w125 Section"
        }
        ; Make a new row ever 2 "controls"
        else if (mod(newSection, 2) = 1) {
            opts := "xs w125 Section"
        }
        ; Otherwise the next is in a new column
        else {
            opts := "ys w125"
        }
        eduGui.Add("Text", opts, item.name)
        eduGui.Add("Edit", "ys-3 w75 Limit ReadOnly", item.default)
        ; Note: The "-2" option is recommended when creating non-unitary UpDown controls, because
        ; it prevents a glitch that may otherwise occur when the control is greatly solicited
        ; (e.g. when using the mouse wheel to scroll the value).
        ; It disables the control's UDS_SETBUDDYINT style flag.
        eduGui.Add("UpDown", "-2")
        eduGui.Add("Text", "ys w100", item.refRange " " item.units)
    }
}
; "Show" the second form GUI but have it hidden initially
eduGui.Show("x0 y50 h" guiH - 50 " w" guiW - scrollW " hide")

;**************************************************************************************************
; Show the main GUI
;**************************************************************************************************
mainGui.Show("h" guiH " w" guiW)

;Scrolling
OnMessage(0x114, "OnScroll") ; WM_HSCROLL
OnMessage(0x115, "OnScroll") ; WM_VSCROLL
OnMessage(0x020A, "OnWheel") ; WM_MOUSEWHEEL

; Used to intercept the UpDown UDN_DELTAPOS notification
OnMessage(0x004E, "WM_NOTIFY") ;WM_NOTIFY

Return ; Auto-execute section

;**************************************************************************************************
; Functions
;**************************************************************************************************
MainSize(guiObj, MinMax, w, h) {
    global labsGui, eduGui
    SetWinDelay(0)
    
    WinMove(0, 50, w, h - 50, "ahk_id " labsGui.hwnd)
    WinMove(0, 50, w, h - 50, "ahk_id " eduGui.hwnd)
}

; Called when the DropDownList of the main GUI is changed.
; This shows/hides the proper child GUIs in response.
DDL(ctrl) {
	global labsGui, eduGui, scrollW
    baseOpts := "x0 y50 h" ctrl.gui.clientPos.h - 50 " w" ctrl.gui.clientPos.w - scrollW
    labsGui.Show(baseOpts (ctrl.value = 1 ? "" : " Hide"))
    eduGui.Show(baseOpts (ctrl.value = 2 ? "" : " Hide"))
    gui := ctrl.value = 1 ? labsGui : eduGui
    UpdateScrollBars(gui.hwnd, gui.clientPos.w, gui.clientPos.h)
    Return
}

; Click handler for main GUI's button
InsertData(ctrl) {
    global labsGui, eduGui
    
    ; Not sure why I am needing this but the key is still read as down in the while loop later on
    while (GetKeyState("Enter")) {
        sleep(50)
    }
    
    ; Minimize the button's GUI
    ctrl.gui.Minimize()
    
    ; Show a new "splash" GUI that is semi-transparent informing the user what to do
    splashGui := GuiCreate("+ToolWindow +AlwaysOnTop", "Data Entry")
    splashGui.MarginX := 10
    splashGui.Add("Text", "Center w300", "Please click in the first cell of the Labs Cerner Test Patient Use Only powerform.`n`nHit Enter when ready to send data.`nHit Escape to cancel.")
    splashGui.Show()
	WinSetTransparent(200, "ahk_id " splashGui.hwnd)
    
    ; Wait for either the Enter or Escape
    while (!(GetKeyState("Enter") || GetKeyState("Esc"))) {
		sleep(50)
	}
    ; User canceled out of it
    if (A_PriorKey = "Escape") {
        splashGui.Destroy()
        ctrl.gui.Restore()
        return
    }
    
    ; Kill the "splash" GUI
	splashGui.Destroy()
	Sleep(500)
    
    ; Check which item is selected in the DropDownList
	If (ctrl.gui.control["Form"].value = 1) {
		childGui := labsGui
		ICUInd := labsGui.control["includeIcu"].value
	}
	Else {
		childGui := eduGui
	}
    
    ; Loop over the child GUI's controls
    for h, gCtrl in childGui {
        ; break if we hit the ICU Labs divider and the checkbox is not checked
        if (gCtrl.text = "ICU Labs" && !ICUInd) {
            Break
        }
        
        ; Only care about edit controls
        if (gCtrl.type = "Edit") {
            SendInput(gCtrl.Text "{Enter}")
            Sleep(100)
        }
    }
    
    ; restore the main GUI
	ctrl.gui.Restore()
    Return
}

;Used for scrolling GUIs with controls on it
; Below two functions based heavily on code by Lexikos - https://autohotkey.com/board/topic/26033-scrollable-gui-proof-of-concept/#entry168174
UpdateScrollBars(guihwnd, GuiWidth, GuiHeight) {
    static SIF_RANGE := 0x1, SIF_PAGE:= 0x2, SIF_DISABLENOSCROLL := 0x8, SB_HORZ := 0, SB_VERT := 1
    
    ; Calculate scrolling area.
    Left := Top := 9999
    Right := Bottom := 0
    for ctlHwnd, ctlObj in GuiFromHwnd(guiHwnd) {
        pos := ctlObj.pos
        if (pos.x < Left)
            Left := pos.x
        if (pos.y < Top)
            Top := pos.y
        if (pos.x + pos.w > Right)
            Right := pos.x + pos.w
        if (pos.y + pos.h > Bottom)
            Bottom := pos.y + pos.h
    }
    ; Is the offset for the GUI's margin?
    Left -= 8
    Top -= 8
    Right += 8
    Bottom += 8
    ScrollWidth := Right-Left
    ScrollHeight := Bottom-Top
    
    ; Initialize SCROLLINFO.
    VarSetCapacity(si, 28, 0)
    NumPut(28, si) ; cbSize
    NumPut(SIF_RANGE | SIF_PAGE, si, 4) ; fMask
    
    ; Update horizontal scroll bar.
    NumPut(ScrollWidth, si, 12) ; nMax
    NumPut(GuiWidth, si, 16) ; nPage
    DllCall("SetScrollInfo", "ptr", guiHwnd, "uint", SB_HORZ, "ptr", &si, "int", 1)
    
    ; Update vertical scroll bar.
    ; NumPut(SIF_RANGE | SIF_PAGE | SIF_DISABLENOSCROLL, si, 4) ; fMask - causes the scroll bar to be disabled rather than hidden when it is not needed. 
    NumPut(ScrollHeight, si, 12) ; nMax
    NumPut(GuiHeight, si, 16) ; nPage
    DllCall("SetScrollInfo", "ptr", guiHwnd, "uint", SB_VERT, "ptr", &si, "int", 1)
    
    if (Left < 0 && Right < GuiWidth)
        x := Abs(Left) > GuiWidth-Right ? GuiWidth-Right : Abs(Left)
    if (Top < 0 && Bottom < GuiHeight)
        y := Abs(Top) > GuiHeight-Bottom ? GuiHeight-Bottom : Abs(Top)
    if (x || y)
        DllCall("ScrollWindow", "ptr", guiHwnd, "int", x, "int", y, "uint", 0, "uint", 0)
}

; Handles WM_MOUSEWHEEL messages
; Can use the shift key to allow for horizontal scrolling
; Still need to implement WM_MOUSEHWHEEL
; Based on code for just me's Class_ScrollGui - https://github.com/AHK-just-me/Class_ScrollGUI
OnWheel(wParam, lParam, msg, hwnd) {
    global labsGui, eduGui
    
    ; Only scroll if the mouse is over the child GUIs
    if !(hwnd = labsGui.hwnd || hwnd = eduGui.hwnd) {
        return false
    }
    
    ; Determines which direction to scroll, up or down
    SB := ((wParam >> 16) > 0x7FFF) || (wParam < 0) ? 1 : 0
    
    ; If Shift is held down, send the msg for horizontal scrolling
    dir := GetKeyState("Shift") ? 0x114 : 0x115
    
    ; Execute the scroll
    OnScroll(SB, 0, dir, hwnd)
}

;Used for scrolling GUIs with controls on it 
OnScroll(wParam, lParam, msg, hwnd) {
    static SIF_ALL := 0x17, SCROLL_STEP := 30
    bar := msg = 0x114 ? 0 : 1 ; SB_HORZ=0, SB_VERT=1
    
    VarSetCapacity(si, 28, 0)
    NumPut(28, si) ; cbSize
    NumPut(SIF_ALL, si, 4) ; fMask
    if !DllCall("GetScrollInfo", "ptr", hwnd, "int", bar, "ptr", &si, "UInt") {
        return
    }
    
    VarSetCapacity(rect, 16)
    DllCall("GetClientRect", "ptr", hwnd, "ptr", &rect)
    
    new_pos := NumGet(si, 20, "Int") ; nPos
    
    action := wParam & 0xFFFF
    ; ToolTip(action)
    if (action = 0) ; SB_LINEUP
        new_pos -= SCROLL_STEP
    else if (action = 1) ; SB_LINEDOWN
        new_pos += SCROLL_STEP
    else if (action = 2) ; SB_PAGEUP
        new_pos -= NumGet(rect, 12, "int") - SCROLL_STEP
    else if (action = 3) ; SB_PAGEDOWN
        new_pos += NumGet(rect, 12, "int") - SCROLL_STEP
    else if (action = 5 || action = 4) ; SB_THUMBTRACK || SB_THUMBPOSITION
        new_pos := wParam>>16
    else if (action = 6) ; SB_TOP
        new_pos := NumGet(si, 8, "int") ; nMin
    else if (action = 7) ; SB_BOTTOM
        new_pos := NumGet(si, 12, "int") ; nMax
    else
        return
    
    min := NumGet(si, 8, "int") ; nMin
    max := NumGet(si, 12, "int") - NumGet(si, 16, "Int") ; nMax-nPage
    new_pos := new_pos > max ? max : new_pos
    new_pos := new_pos < min ? min : new_pos
    
    old_pos := NumGet(si, 20, "int") ; nPos
    
    x := y := 0
    if (bar = 0) ; SB_HORZ
        x := old_pos-new_pos
    else
        y := old_pos-new_pos
    ; Scroll contents of window and invalidate uncovered area.
    DllCall("ScrollWindow", "ptr", hwnd, "int", x, "int", y, "uint", 0, "uint", 0)
    
    ; Update scroll bar.
    NumPut(new_pos, si, 20, "int") ; nPos
    DllCall("SetScrollInfo", "ptr", hwnd, "int", bar, "ptr", &si, "int", 1)
}

; Adapted from http://numeric.nerim.net/AutoHotkey/Scripts/UpDown%20-%20Non-unitary%20increments.ahk
WM_NOTIFY(wParam, lParam, Msg, hWnd)
{
   static UDM_GETBUDDY := 0x046A, UDN_DELTAPOS := 0xFFFFFD2E, ctrls := {}

   udHwnd := NumGet(lParam + 0, 0, "UInt")
   udCode := NumGet(lParam + 0, A_PtrSize*2, "UInt")
   iDelta := NumGet(lParam + 0, A_PtrSize*3 + 4, "Int")

    If (udCode = UDN_DELTAPOS) {
        If (editHwnd := DllCall("User32\SendMessage", "Ptr", udHwnd, "UInt", UDM_GETBUDDY, "UInt", 0, "UInt", 0)) {
            ctrlObj := guictrlfromhwnd(editHwnd)
            ; Save the controls precision for later retrieval
            if (!ctrls.HasKey(editHwnd)) {
                ctrls[editHwnd] := StrLen(StrSplit(ctrlObj.text, ".")[2])
            }
            precision := ctrls[editHwnd]
            factor := precision = 0 ? 1 : precision = 1 ? 0.1 : 0.01
            min := precision = 0 ? 0 : precision = 1 ? 0.0 : format("{:.2f}", 0.00)
        
            newText := format("{:0." precision "f}", ctrlObj.text + 0)
            newText := format("{:0." precision "f}", newText + factor * iDelta)
            newText := (newText < min) ? min : newText
            ctrlObj.text := newText
        
            ; Done; discard proposed change
            Return True
        }
        Else {
            ; No buddy control
            Return False
        }
    }
    Else {
        ; Not UDN_DELTAPOS, or unit-incremented UpDown control
        Return False
    }
}
JSON.ahk
(11.55 KiB) Downloaded 178 times
Here is the JSON data file:

Code: Select all

{
    "fields1": [
        {
            "Name": "PT Level",
            "Default": "10.1",
            "RefRange": "8.6 - 12.2",
            "Units": "sec"
        },
        {
            "Name": "Hgb",
            "Default": "14",
            "RefRange": "12 - 16",
            "Units": "g/dL"
        },
        {
            "Name": "PTT Level",
            "Default": "24",
            "RefRange": "26 - 36",
            "Units": "sec"
        },
        {
            "Name": "HCT",
            "Default": "43.7",
            "RefRange": "35.4 - 47",
            "Units": "%"
        },
        {
            "Name": "INR",
            "Default": "1.03",
            "RefRange": "0.9 - 1.2",
            "Units": ""
        },
        {
            "Name": "Platelet Count",
            "Default": "405",
            "RefRange": "150 - 400",
            "Units": "K/uL"
        },
        {
            "Name": "WBC",
            "Default": "8.2",
            "RefRange": "3.6 - 10",
            "Units": "K/uL"
        },
        {
            "Name": "_DIVIDER",
            "Text": ""
        },
        {
            "Name": "Sodium",
            "Default": "140",
            "RefRange": "136 - 144",
            "Units": "mmol/L"
        },
        {
            "Name": "BUN",
            "Default": "12",
            "RefRange": "10 - 23",
            "Units": "mg/dL"
        },
        {
            "Name": "Potassium",
            "Default": "4.6",
            "RefRange": "3.4 - 5",
            "Units": "mmol/L"
        },
        {
            "Name": "Creatinine",
            "Default": "1.1",
            "RefRange": "0.6 - 1.1",
            "Units": "mg/dL"
        },
        {
            "Name": "Chloride",
            "Default": "112",
            "RefRange": "96 - 100",
            "Units": "mmol/L"
        },
        {
            "Name": "Bicarb",
            "Default": "23",
            "RefRange": "22 - 32",
            "Units": "mmol/L"
        },
        {
            "Name": "_DIVIDER",
            "Text": ""
        },
        {
            "Name": "Bedside Glucose",
            "Default": "89",
            "RefRange": "70 - 100",
            "Units": "mg/dL"
        },
        {
            "Name": "Glucose Assay",
            "Default": "91",
            "RefRange": "",
            "Units": "mg/dL"
        },
        {
            "Name": "_DIVIDER",
            "Text": ""
        },
        {
            "Name": "Troponin I",
            "Default": "0.03",
            "RefRange": "0.00 - 0.10",
            "Units": "ng/mL"
        },
        {
            "Name": "AST/GOT",
            "Default": "42",
            "RefRange": "8 - 36",
            "Units": ""
        },
        {
            "Name": "Digoxin Assay",
            "Default": "1.4",
            "RefRange": "0.8 - 2.0",
            "Units": ""
        },
        {
            "Name": "ALT/SGPT",
            "Default": "12",
            "RefRange": "7 - 38",
            "Units": ""
        },
        {
            "Name": "Calcium",
            "Default": "9.1",
            "RefRange": "8.5 - 10.1",
            "Units": "mg/dL"
        },
        {
            "Name": "Total Bili",
            "Default": "0.9",
            "RefRange": "0.2 - 1.1",
            "Units": ""
        },
        {
            "Name": "Magnesium",
            "Default": "1.7",
            "RefRange": "1.5 - 2.1",
            "Units": "mEq/L"
        },
        {
            "Name": "Bilirubin Direct",
            "Default": "0.1",
            "RefRange": "0 - 0.5",
            "Units": "mg/dL"
        },
        {
            "Name": "_DIVIDER",
            "Text": "Arterial Blood Gases"
        },
        {
            "Name": "pH",
            "Default": "7.43",
            "RefRange": "7.35 - 7.45",
            "Units": "unit"
        },
        {
            "Name": "HCO3",
            "Default": "29",
            "RefRange": "22 - 28",
            "Units": "mmol/L"
        },
        {
            "Name": "pCO2",
            "Default": "3.8",
            "RefRange": "3.5 - 4.5",
            "Units": "mmHg"
        },
        {
            "Name": "Base Deficit",
            "Default": "2.3",
            "RefRange": "0 - 4.0",
            "Units": "mmol/L"
        },
        {
            "Name": "pO2",
            "Default": "77",
            "RefRange": "75 - 100",
            "Units": "mmHg"
        },
        {
            "Name": "O2 Saturation, Calc ABG",
            "Default": "98",
            "RefRange": "94 - 100",
            "Units": "%"
        },
        {
            "Name": "O2 Saturation, Meas ABG",
            "Default": "98",
            "RefRange": "94 - 100",
            "Units": "%"
        },
        {
            "Name": "FIO2",
            "Default": "97",
            "RefRange": "",
            "Units": "%"
        },
        {
            "Name": "_DIVIDER",
            "Text": "ICU Labs"
        },
        {
            "Name": "CK Total",
            "Default": "123",
            "RefRange": "38 - 234",
            "Units": "U/L"
        },
        {
            "Name": "Total Protein",
            "Default": "7.7",
            "RefRange": "6.4 - 8.3",
            "Units": "g/dL"
        },
        {
            "Name": "Myoglobin",
            "Default": "93",
            "RefRange": "0 - 88",
            "Units": "ng/mL"
        },
        {
            "Name": "Albumin Assay",
            "Default": "4.6",
            "RefRange": "3.5 - 5",
            "Units": "g/dL"
        },
        {
            "Name": "BNP",
            "Default": "94",
            "RefRange": "< 100",
            "Units": "pg/mL"
        },
        {
            "Name": "Ionized Calcium",
            "Default": "5.2",
            "RefRange": "4.5 - 5.3",
            "Units": "mg/dL"
        },
        {
            "Name": "SVO2",
            "Default": "67",
            "RefRange": "",
            "Units": "%"
        },
        {
            "Name": "Osmality Serum",
            "Default": "283",
            "RefRange": "270 - 300",
            "Units": "mOsm/kg"
        },
        {
            "Name": "Lactic Acid",
            "Default": "2.1",
            "RefRange": "0.9 - 1.7",
            "Units": "mmol/L"
        },
        {
            "Name": "Osmality Urine",
            "Default": "1234",
            "RefRange": "400 - 1300",
            "Units": "mOsm/kg"
        },
        {
            "Name": "Phosphorus",
            "Default": "3.6",
            "RefRange": "3.5 - 4.5",
            "Units": "mg/dL"
        },
        {
            "Name": "Cortisol, Random",
            "Default": "19",
            "RefRange": "",
            "Units": "ug/dL"
        },
        {
            "Name": "Alkaline Phos",
            "Default": "151",
            "RefRange": "38 - 126",
            "Units": "U/L"
        }
    ],
    "fields2": [
        {
            "Name": "PT Level",
            "Default": "10.1",
            "RefRange": "8.6 - 12.2",
            "Units": "sec"
        },
        {
            "Name": "Hgb",
            "Default": "14",
            "RefRange": "12 - 16",
            "Units": "g/dL"
        },
        {
            "Name": "PTT Level",
            "Default": "24",
            "RefRange": "26 - 36",
            "Units": "sec"
        },
        {
            "Name": "HCT",
            "Default": "43.7",
            "RefRange": "35.4 - 47",
            "Units": "%"
        },
        {
            "Name": "INR",
            "Default": "1.03",
            "RefRange": "0.9 - 1.2",
            "Units": ""
        },
        {
            "Name": "WBC",
            "Default": "8.2",
            "RefRange": "3.6 - 10",
            "Units": "K/uL"
        },
        {
            "Name": "_DIVIDER",
            "Text": ""
        },
        {
            "Name": "Sodium",
            "Default": "140",
            "RefRange": "136 - 144",
            "Units": "mmol/L"
        },
        {
            "Name": "BUN",
            "Default": "12",
            "RefRange": "10 - 23",
            "Units": "mg/dL"
        },
        {
            "Name": "Creatinine",
            "Default": "1.1",
            "RefRange": "0.6 - 1.1",
            "Units": "mg/dL"
        },
        {
            "Name": "Potassium",
            "Default": "4.6",
            "RefRange": "3.4 - 5",
            "Units": "mmol/L"
        },
        {
            "Name": "Lactic Acid",
            "Default": "2.1",
            "RefRange": "0.9 - 1.7",
            "Units": "mmol/L"
        },
        {
            "Name": "Chloride",
            "Default": "112",
            "RefRange": "96 - 100",
            "Units": "mmol/L"
        },
        {
            "Name": "ESR",
            "Default": "21",
            "RefRange": "0-22 male | 0-29 female",
            "Units": ""
        },
        {
            "Name": "Total CO2",
            "Default": "23",
            "RefRange": "22 - 32",
            "Units": "mmol/L"
        },
        {
            "Name": "CRP",
            "Default": "3.2",
            "RefRange": "< 3.0",
            "Units": "mg/L"
        },
        {
            "Name": "_DIVIDER",
            "Text": ""
        },
        {
            "Name": "Bedside Glucose",
            "Default": "89",
            "RefRange": "70 - 100",
            "Units": "mg/dL"
        },
        {
            "Name": "Fasting Glucose",
            "Default": "91",
            "RefRange": "",
            "Units": "mg/dL"
        },
        {
            "Name": "_DIVIDER",
            "Text": ""
        },
        {
            "Name": "Troponin I",
            "Default": "0.03",
            "RefRange": "0.00 - 0.10",
            "Units": "ng/mL"
        },
        {
            "Name": "AST/GOT",
            "Default": "42",
            "RefRange": "8 - 36",
            "Units": ""
        },
        {
            "Name": "Digoxin Assay",
            "Default": "1.4",
            "RefRange": "0.8 - 2.0",
            "Units": ""
        },
        {
            "Name": "ALT/SGPT",
            "Default": "12",
            "RefRange": "7 - 38",
            "Units": ""
        },
        {
            "Name": "Calcium",
            "Default": "9.1",
            "RefRange": "8.5 - 10.1",
            "Units": "mg/dL"
        },
        {
            "Name": "Total Bili",
            "Default": "0.9",
            "RefRange": "0.2 - 1.1",
            "Units": ""
        },
        {
            "Name": "Magnesium",
            "Default": "1.7",
            "RefRange": "1.5 - 2.1",
            "Units": "mEq/L"
        },
        {
            "Name": "Alk Phos",
            "Default": "151",
            "RefRange": "38 - 126",
            "Units": "U/L"
        },
        {
            "Name": "_DIVIDER",
            "Text": ""
        },
        {
            "Name": "pH ABG",
            "Default": "7.43",
            "RefRange": "7.35 - 7.45",
            "Units": "unit"
        },
        {
            "Name": "HCO3",
            "Default": "29",
            "RefRange": "22 - 28",
            "Units": "mmol/L"
        },
        {
            "Name": "pCO2",
            "Default": "3.8",
            "RefRange": "3.5 - 4.5",
            "Units": "mmHg"
        },
        {
            "Name": "FIO2",
            "Default": "97",
            "RefRange": "",
            "Units": "%"
        },
        {
            "Name": "Base Deficit",
            "Default": "2.3",
            "RefRange": "0 - 4.0",
            "Units": "mmol/L"
        },
        {
            "Name": "pO2 ABG",
            "Default": "77",
            "RefRange": "62 - 78",
            "Units": ""
        }
    ]
}
Last edited by kczx3 on 10 Apr 2018, 12:49, edited 4 times in total.

Helgef
Posts: 4709
Joined: 17 Jul 2016, 01:02
Contact:

Re: [v2 Showcase] Script displaying some of AHKv2's usage and syntax

Post by Helgef » 30 Mar 2018, 11:44

Happy too see v2 stuff, and this looks very good. Impressive with the scrolling gui :o . You could write a scroll tutorial or share some general code for it. The wheel hotkeys causes maxhotkeysperintervall error quite easy.

Cheers, and thanks for sharing :clap: :thumbup:.

User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

Re: [v2 Showcase] Script displaying some of AHKv2's usage and syntax

Post by jeeswg » 30 Mar 2018, 12:08

- It's a great looking GUI, thanks for sharing. Haha, @Helgef, I was thinking the same, I've been asking about (and asked about) scrolling GUIs before, and was wondering if we could extract from this the most basic scrolling GUI example script ever. I noticed that a ScrollWindow Winapi function was used. Cheers.
- It's for similar reasons to this script that I created my GUI control zoo (all the animals (controls) in one place, where you can take a look at them).
control zoo (AHK v2) - AutoHotkey Community
https://autohotkey.com/boards/viewtopic ... 37&t=41685
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA

User avatar
kczx3
Posts: 1649
Joined: 06 Oct 2015, 21:39

Re: [v2 Showcase] Script displaying some of AHKv2's usage and syntax

Post by kczx3 » 30 Mar 2018, 13:13

Helgef wrote:Happy too see v2 stuff, and this looks very good. Impressive with the scrolling gui :o . You could write a scroll tutorial or share some general code for it. The wheel hotkeys causes maxhotkeysperintervall error quite easy.
Thanks! As is mentioned in the code comments, it was largely adapted from code by Lexikos. The url is in there as well. To avoid the MaxHotkeysPerInterval error, I'll probably look into actually hooking the WM_MOUSEWHEEL and WM_MOUSEHWHEEL messages like 'just me' did in his class_scrollgui

User avatar
kczx3
Posts: 1649
Joined: 06 Oct 2015, 21:39

Re: [v2 Showcase] Script displaying some of AHKv2's usage and syntax

Post by kczx3 » 30 Mar 2018, 20:07

@Helgef - Updated to handle WM_MOUSEWHEEL messages instead of using hotkeys.

Himmilayah

Re: [v2 Showcase] Script displaying some of AHKv2's usage and syntax

Post by Himmilayah » 30 Mar 2018, 23:22

Getting the following error, I am running the latest ahk on windows 10 6
bit

Line (17) : ==> Call to nonexistent function.
Specifically: SysGet(2)

gregster
Posts: 9113
Joined: 30 Sep 2013, 06:48

Re: [v2 Showcase] Script displaying some of AHKv2's usage and syntax

Post by gregster » 31 Mar 2018, 03:44

Himmilayah wrote:Getting the following error, I am running the latest ahk on windows 10 6
bit
That would be version 1.1.28.00 ?!? Like mentioned above, this is for the v2 alpha version...

burque505
Posts: 1736
Joined: 22 Jan 2017, 19:37

Re: [v2 Showcase] Script displaying some of AHKv2's usage and syntax

Post by burque505 » 31 Mar 2018, 10:46

Do I have the wrong V2?
AHK_Versions.PNG
AHK_Versions.PNG (1.08 KiB) Viewed 5512 times
(Ahk-Exe-Swapper reports AHK_H as AHK_L, but it is AHK_H)
I get this error with the real AHK_L version:
Error.PNG
Error.PNG (54.29 KiB) Viewed 5512 times
Regards,
burque505

User avatar
nnnik
Posts: 4500
Joined: 30 Sep 2013, 01:01
Location: Germany

Re: [v2 Showcase] Script displaying some of AHKv2's usage and syntax

Post by nnnik » 31 Mar 2018, 11:08

Yeah your version is too old.
This is for 2.0-a090+
Recommends AHK Studio

burque505
Posts: 1736
Joined: 22 Jan 2017, 19:37

Re: [v2 Showcase] Script displaying some of AHKv2's usage and syntax

Post by burque505 » 31 Mar 2018, 12:18

Switched to 2.0-a090, works great!
But ... :cry:
Today's release, 2.0-a091:
Error 2 a091.PNG
Error 2 a091.PNG (89.37 KiB) Viewed 5487 times

User avatar
kczx3
Posts: 1649
Joined: 06 Oct 2015, 21:39

Re: [v2 Showcase] Script displaying some of AHKv2's usage and syntax

Post by kczx3 » 31 Mar 2018, 12:34

Interesting. I haven’t tried it with build 91. I don’t have access to a computer for the next week. Apologies.

burque505
Posts: 1736
Joined: 22 Jan 2017, 19:37

Re: [v2 Showcase] Script displaying some of AHKv2's usage and syntax

Post by burque505 » 31 Mar 2018, 12:38

Very nice work, kczx3!
The new build constitutes circumstances beyond your control, of course.
Have a great holiday weekend.
Regards,
burque505

User avatar
kczx3
Posts: 1649
Joined: 06 Oct 2015, 21:39

Re: [v2 Showcase] Script displaying some of AHKv2's usage and syntax

Post by kczx3 » 01 Apr 2018, 06:43

Can anyone try this on 2.0-a092?

User avatar
haichen
Posts: 631
Joined: 09 Feb 2014, 08:24

Re: [v2 Showcase] Script displaying some of AHKv2's usage and syntax

Post by haichen » 01 Apr 2018, 07:22

what json lib do you use?

User avatar
kczx3
Posts: 1649
Joined: 06 Oct 2015, 21:39

Re: [v2 Showcase] Script displaying some of AHKv2's usage and syntax

Post by kczx3 » 01 Apr 2018, 07:31

shoot. Apologies. Forgot that I moved the data to a Jason file. Won’t be able to include a sample dataset till the week of April 9th as I am out of town.

burque505
Posts: 1736
Joined: 22 Jan 2017, 19:37

Re: [v2 Showcase] Script displaying some of AHKv2's usage and syntax

Post by burque505 » 01 Apr 2018, 08:18

Working on 2.0-a092, seems to be just like 2.0-a090. Win7 64-bit SP1.
Regards,
burque505

User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

Re: [v2 Showcase] Script displaying some of AHKv2's usage and syntax

Post by jeeswg » 01 Apr 2018, 10:01

OK, a simple scroll window example. I had thought that scrolling windows would be achievable via multiple ControlMoves, but it wouldn't be pretty. Much better with the ScrollWindow Winapi function.

Code: Select all

;AHK v2

;scroll window example

#SingleInstance force
oGui := GuiCreate(, "MyWinTitle")
oGui.OnEvent("Close", "Gui_Close")
hGui := oGui.hWnd

Loop 20
	oCtl%A_Index% := oGui.Add("Edit",, "EDIT " A_Index)
vLimY1 := 0
vLimY2 := 300

oGui.Show("h300")
return

;==================================================

q:: ;scroll down
w:: ;scroll up
vOffsetX := 0
vOffsetY := 10
if InStr(A_ThisHotkey, "w")
	vOffsetY *= -1
;MsgBox oCtl20.pos.y+oCtl20.pos.h
if ((vOffsetY > 0) && (oCtl1.pos.y < vLimY1))
|| ((vOffsetY < 0) && (oCtl20.pos.y+oCtl20.pos.h+5 > vLimY2))
	DllCall("user32\ScrollWindow", Ptr,hGui, Int,vOffsetX, Int,vOffsetY, Ptr,0, Ptr,0)
return

e:: ;scroll down
r:: ;scroll up
vOffsetX := 0
vOffsetY := 10
if InStr(A_ThisHotkey, "r")
	vOffsetY *= -1
;MsgBox oCtl20.pos.y+oCtl20.pos.h
if ((vOffsetY > 0) && (oCtl1.pos.y+oCtl1.pos.h+5 < vLimY2))
|| ((vOffsetY < 0) && (oCtl20.pos.y > vLimY1))
	DllCall("user32\ScrollWindow", Ptr,hGui, Int,vOffsetX, Int,vOffsetY, Ptr,0, Ptr,0)
return

;==================================================

Gui_Close()
{
	ExitApp()
}
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA

burque505
Posts: 1736
Joined: 22 Jan 2017, 19:37

Re: [v2 Showcase] Script displaying some of AHKv2's usage and syntax

Post by burque505 » 01 Apr 2018, 11:50

Nice, jeeswg.
My humble addition, changing the scroll keys to up and down arrows, making the GUI a little wider:
Spoiler
Jeeswg_scroll.gif
Jeeswg_scroll.gif (80.35 KiB) Viewed 5380 times
(Yes, I AM the kind of person who watches the dryer spin and UltraDefrag at work. ;) )

User avatar
evilC
Posts: 4824
Joined: 27 Feb 2014, 12:30

Re: [v2 Showcase] Script displaying some of AHKv2's usage and syntax

Post by evilC » 03 Apr 2018, 11:37

Helgef wrote:Impressive with the scrolling gui
But the scrolling gui is not in any way included in v2?
It's just a standard DllCall implementation from what I can tell, no different to how you would implement this in a v1 script.
This code belongs in the AHK source code, not in each AHK script.
I bet the CPU usage on that is not great, and it is not as smooth as the AHK_H v1 implementation.

User avatar
kczx3
Posts: 1649
Joined: 06 Oct 2015, 21:39

Re: [v2 Showcase] Script displaying some of AHKv2's usage and syntax

Post by kczx3 » 03 Apr 2018, 19:51

Maybe someday it’ll get added to v2. As of yet, I’ve only had this one use case though. And I think it works well for my needs

Post Reply

Return to “Scripts and Functions (v2)”