{"id":18864844,"url":"https://github.com/hi5/dpi","last_synced_at":"2026-02-11T15:30:17.635Z","repository":{"id":150288455,"uuid":"105925213","full_name":"hi5/dpi","owner":"hi5","description":"DPI() - function for writing friendlier DPI-Aware AutoHotkey GUIs","archived":false,"fork":false,"pushed_at":"2018-09-28T22:23:07.000Z","size":13,"stargazers_count":11,"open_issues_count":0,"forks_count":1,"subscribers_count":4,"default_branch":"master","last_synced_at":"2024-12-30T21:42:35.265Z","etag":null,"topics":["autohotkey","desktop-scaling-factor","dpi","gui","scale"],"latest_commit_sha":null,"homepage":"https://autohotkey.com/boards/viewtopic.php?f=6\u0026t=37913","language":"AutoHotkey","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/hi5.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-10-05T18:25:27.000Z","updated_at":"2024-08-28T06:55:08.000Z","dependencies_parsed_at":"2023-06-18T16:56:48.495Z","dependency_job_id":null,"html_url":"https://github.com/hi5/dpi","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hi5%2Fdpi","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hi5%2Fdpi/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hi5%2Fdpi/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hi5%2Fdpi/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/hi5","download_url":"https://codeload.github.com/hi5/dpi/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":239808522,"owners_count":19700451,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["autohotkey","desktop-scaling-factor","dpi","gui","scale"],"created_at":"2024-11-08T04:44:13.038Z","updated_at":"2026-02-11T15:30:17.581Z","avatar_url":"https://github.com/hi5.png","language":"AutoHotkey","readme":"# DPI() - function for writing friendlier DPI-Aware AutoHotkey GUIs\n\nDPI() can help you quickly transform your current GUI code to make it (more) DPI-Aware making your UI looks consistent\nacross a wide variety of DPI display settings. It hopefully avoids \"illegible\" text or buttons.  \nIt can either return the scaling factor **or** calculate position/values for AHK controls (font size, position (x y), width, height).\n\nAutoHotkey forum: https://autohotkey.com/boards/viewtopic.php?f=6\u0026t=37913  \nSome more background info on the purpose of DPI() posted here https://autohotkey.com/boards/viewtopic.php?p=218669#p218669\n\nPreview - screenshots at 144 DPI (150%) before and after using DPI(): \n![before and after](https://raw.githubusercontent.com/hi5/_resources/master/before-after-dpi.png \"before - after\")\n\n## DPI and the Desktop Scaling Factor\n\n*  96 DPI = 100% scaling\n* 120 DPI = 125% scaling\n* 144 DPI = 150% scaling\n* 192 DPI = 200% scaling\n\nSource and more info at https://msdn.microsoft.com/en-us/library/windows/desktop/dn469266(v=vs.85).aspx\n\n## Parameters\n\n### *DPI([in,setdpi])*\n\n__in__\n\n\u003e When empty it returns the scaling factor. Otherwise it will parse the options\n\u003e and update the numeric values based on the scaling factor.  \n\u003e Example: \"w100\", scaling is 125% -\u003e 100 * 1.25 = 125 -\u003e the returned string is \"w125\"\n\n__setdpi__\n\n\u003e For testing purposes you can set the DPI value to use.  \n\u003e Example: If your current DPI is 120 (125%) and you would like to test 150% scaling\n\u003e use ```dpi(,144)```.  \n\u003e If you want to (temporarily) disable dpi() use ```dpi(,96)```.   \n\u003e (see \"DPI and the Desktop Scaling Factor\" above)\n\n## Notes\n\n* Although DPI scaling is enabled by default - see https://autohotkey.com/docs/commands/Gui.htm#DPIScale - and it scales properly, the end result can still be \"too small\" to be friendly to use, hence DPI(). See forum posts here https://autohotkey.com/boards/viewtopic.php?p=218669#p218669 for some further discussion.\n* Tip: Define a font size for all your GUIs, that way you can easily use DPI() to also scale the font size. See GuiDefaultFont() code below by SKAN on how to obtain the current default font/fontsize.\n* DPI() will use the DPI setting reported by the system in use for the primary screen. If you have a multimonitor setup with different settings for each monitor it may not work correctly.\n* Possible room for improvement: In recent editions of Windows 10 you can now set the DPI scaling per monitor. Currently dpi() will use the DPI scaling reported by the system in use for the _primary screen_. So in theory it could be improved by trying to detect which monitor the GUI will appear on first (or create a helper function for example) and try to read the DPI from the correct registry key `HKEY_CURRENT_USER\\Control Panel\\Desktop\\PerMonitorSettings\\` - see comment here https://autohotkey.com/boards/viewtopic.php?p=219034#p219034\n\n## Code Examples\n\n### Example 1\n\nGet the scaling factor like so:\n\n```autohotkey\nfactor:=dpi() ; will be 1.250000 at 120 DPI\n```\n\n### Example 2\n\nIf this is your current GUI code:\n\n```autohotkey\nGui, Font, s10\nGui, Add, Text, x5 y5, Hello\nGui, Add, Edit, xp yp+20 w200 h100 vVar, Goodbye\nGui, Add, Button, xp yp+110 w100 gMyLabel, OK\nGui, Add, Button, xp+110 yp w50 gGuiClose, Cancel\nGui, Show, w220 h200, DPI() test GUI\nReturn\n\nMyLabel:\nGui, Submit, Destroy\nMsgBox % var\nGosub, GuiClose\nReturn\n\nEsc::\nGuiClose:\nExitApp\n```\n\nYou can simply call the **dpi()** function by wrapping it arround the Gui command options like so:\n\n```autohotkey\nGui, Font, % dpi(\"s10\")\nGui, Add, Text, % dpi(\"x5 y5\"), Hello\nGui, Add, Edit, % dpi(\"xp yp+20 w200 h100 vVar\"), Goodbye\nGui, Add, Button, % dpi(\"xp yp+110 w100 gMyLabel\"), OK\nGui, Add, Button, % dpi(\"xp+110 yp w50 gGuiClose\"), Cancel\nGui, Show, % dpi(\"w220 h200\"), DPI() test GUI\nReturn\n```\n\n### Example 3\n\nVarious examples on how to call dpi()\n\n```autohotkey\n\nGui, Add, GroupBox, % dpi(\"x16 y7 w540 h45\") , GroupboxTitle\n\nGui, Add, Text,     % dpi(\"x25 y25 w300 h20\") , Text\n\nGui, Add, Edit,     % dpi(\"x25 yp-5 w300 h20 Number vVar\"), EditText\n\nSelectMenuPos:=2\nGui, Add, DropDownList, % dpi(\"xp yp+10 w200 h25 r4 Choose\" SelectMenuPos) \" vVar\", 1 - Option|2 - Option|3 - Option\n; Choose + the SelectMenuPos selects \"2 - Option\" in the DropDownList\n\nCheck:=1\nGui, Add, Checkbox, % dpi(\"x25 yp+20 w200 h16 Checked\" Check \" vVar\"), Option\n; Checked + the Check variable ticks the checkbox\n```\n\n### GuiDefaultFont\n\nCode by SKAN, cleaned up formatting errors from old forum post (simply removed BB color code tags):\n\n```autohotkey\nA_GuiFont     := GuiDefaultFont()\nA_GuiFontSize := A_LastError\n\nGuiDefaultFont() {        ; By SKAN www.autohotkey.com/forum/viewtopic.php?p=465438#465438\n hFont := DllCall( \"GetStockObject\", UInt,17 ) ; DEFAULT_GUI_FONT\n VarSetCapacity( LF, szLF := 60*( A_IsUnicode ? 2:1 ) )\n DllCall(\"GetObject\", UInt,hFont, Int,szLF, UInt,\u0026LF )\n hDC := DllCall( \"GetDC\", UInt,hwnd ), DPI := DllCall( \"GetDeviceCaps\", UInt,hDC, Int,90 )\n DllCall( \"ReleaseDC\", Int,0, UInt,hDC ), S := Round( ( -NumGet( LF,0,\"Int\" )*72 ) / DPI )\nReturn DllCall( \"MulDiv\",Int,\u0026LF+28, Int,1,Int,1, Str ), DllCall( \"SetLastError\", UInt,S )\n}\n```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhi5%2Fdpi","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhi5%2Fdpi","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhi5%2Fdpi/lists"}