追記

野良犬日記 2.1

RDF/RSS
この日記の検索

最近のツッコミ:


2024-01-21 (Sun) [長年日記]

_ [ahk] Ahk2Exe の github action

毎度 yaml 書くの面倒なので https://github.com/tamo/action-Ahk2Exe にまとめた


2024-01-01 (Mon) [長年日記]

_ [js]はてブのコメントもマウスホバーで見たい

YouTube コメントをホバーで一覧するやつ

https://github.com/tamo/yt-comments-popup/compare/v1.2.4...hatena

適当に b.hatena.ne.jp で動くようにした


2023-12-31 (Sun) [長年日記]

_ [ahk] Windows のストアアプリ実体位置など

https://www.sordum.org/16360/ というのがあるそうだけどソースがないので怖くて実行できずにいるので、自分で書いた

gist から github repo へ

最初は gist にしていたんだけど、履歴が見えづらいし gitkraken から無料では使えないみたいだし画像以外の添付ファイルもできないので普通に github 扱いにしたくなって

git remote add 適当な名前 https://github.com/tamo/新規repo
git push 適当な名前 main

で流しこんだ。


2023-12-01 (Fri) [長年日記]

_ [ahk] Rapid なんちゃら 4

WinRestore を何回も呼んだりして気持ち悪いので、GetWindowPlacement を DllCall することにした。

#Requires AutoHotkey v2.0
#Warn
#SingleInstance Force

; A simple workaround for the Rapid HPD problem
; https://devblogs.microsoft.com/directx/avoid-unexpected-app-rearrangement/
; https://superuser.com/questions/1292435

CoordMode("Mouse", "Screen")
Persistent(true)
registerpower()
return

; https://www.autohotkey.com/boards/viewtopic.php?p=539708
registerpower()
{
  CLSID := Buffer(16)
  if (res :=
    DllCall("ole32\CLSIDFromString",
      ; GUID_CONSOLE_DISPLAY_STATE_
      "WStr", "{6FE69556-704A-47A0-8F24-C28D936FDA47}",
      "Ptr", CLSID,
      "UInt")
  ) {
    throw (Error("CLSIDFromString failed. Error: " . Format("{:#x}", res)))
  }

  if (! ;hPowerNotify :=
    DllCall('RegisterPowerSettingNotification',
      'Ptr', A_ScriptHwnd,
      'Ptr', CLSID,
      'UInt', 0,
      'Ptr')
  ) {
    throw (OSError(A_LastError, -1, 'RegisterPowerSettingNotification'))
  }

  Sleep(1) ; a notification is always emitted immediately after registering for it for some reason. this prevents seeing it
  OnMessage(0x218, _WM_POWERBROADCAST)
}

_WM_POWERBROADCAST(wParam, lParam, msg, hwnd) {
  Critical(1000)
  static oldpower := 1
  static newpower
  static wins := Map()

  if (wParam = 0x8013) { ; PBT_POWERSETTINGCHANGE
    newpower := NumGet(lParam, 20, 'UChar') ; 0 (off) or 1 (on).
    switch {
      case (oldpower and !newpower): savewins(&wins)
      case (!oldpower and newpower): restorewins(wins)
    }
    oldpower := newpower
  }
  return (true)
}

savewins(&winmap) {
  winmap.Clear()

  MouseGetPos(&mx, &my)
  winmap["mouse"] := { x: mx, y: my }

  for (this_id in WinGetList(, , "Program Manager")) {
    if (WinExist(this_id)) {
      wp := normalwp(this_id, &x, &y)
      winmap[this_id] := { x: x, y: y, wp: wp }
    }
  }
}

restorewins(winmap) {
  for (this_id, d in winmap) {
    if (this_id = "mouse") {
      MouseMove(d.x, d.y, 0)
      continue
    }

    if (WinExist(this_id)) {
      WinGetPos(&x, &y, , , this_id)
      if (d.x = x && d.y = y) {
        continue
      }
      WinRestore(this_id)
      DllCall("SetWindowPlacement", "Ptr", this_id, "Ptr", d.wp)
    }
  }
}

; https://learn.microsoft.com/windows/win32/api/winuser/ns-winuser-windowplacement
normalwp(hwnd, &x, &y) {
  NumPut("UInt", 44, wp := Buffer(44, 0))
  DllCall("GetWindowPlacement", "Ptr", hwnd, "Ptr", wp)
  x := NumGet(wp, 28, "Int")
  y := NumGet(wp, 32, "Int")
  return wp
}

2023-11-30 (Thu) [長年日記]

_ [ahk] 勝手にウィンドウが動いちゃう問題 その3

最小化ウィンドウは意外と奥が深い。

最小化される直前の状態が普通だったか最大化だったかを調べなければいけない。 つまり、普通→最大化→最小化の場合、WinRestore を 2回撃たなきゃ普通にならない。

もちろん毎秒 WinRestore できるわけもないので、ループはやめた。notify されたときだけ動作するようにした。

#Requires AutoHotkey v2.0
#Warn
#SingleInstance Force

; A simple workaround for the Rapid HPD problem
; https://devblogs.microsoft.com/directx/avoid-unexpected-app-rearrangement/
; https://superuser.com/questions/1292435

Persistent(true)
registerpower()
return

; https://www.autohotkey.com/boards/viewtopic.php?p=539708
registerpower()
{
  CLSID := Buffer(16)
  if (res :=
    DllCall("ole32\CLSIDFromString",
      ; GUID_CONSOLE_DISPLAY_STATE_
      "WStr", "{6FE69556-704A-47A0-8F24-C28D936FDA47}",
      "Ptr", CLSID,
      "UInt")
  ) {
    throw (Error("CLSIDFromString failed. Error: " . Format("{:#x}", res)))
  }

  if (! ;hPowerNotify :=
    DllCall('RegisterPowerSettingNotification',
      'Ptr', A_ScriptHwnd,
      'Ptr', CLSID,
      'UInt', 0,
      'Ptr')
  ) {
    throw (OSError(A_LastError, -1, 'RegisterPowerSettingNotification'))
  }

  Sleep(1) ; a notification is always emitted immediately after registering for it for some reason. this prevents seeing it
  OnMessage(0x218, _WM_POWERBROADCAST)
}

_WM_POWERBROADCAST(wParam, lParam, msg, hwnd) {
  Critical(1000)
  static oldpower := 1
  static newpower
  static wins := Map()

  if (wParam = 0x8013) { ; PBT_POWERSETTINGCHANGE
    newpower := NumGet(lParam, 20, 'UChar') ; 0 (off) or 1 (on).
    switch {
      case (oldpower and !newpower): savewins(&wins)
      case (!oldpower and newpower): restorewins(wins)
    }
    oldpower := newpower
  }
  return (true)
}

savewins(&winmap) {
  winmap.Clear()

  MouseGetPos(&mx, &my)
  winmap["mouse"] := { x: mx, y: my }

  for (this_id in WinGetList(, , "Program Manager")) {
    try {
      minmax := WinGetminmax(this_id)
    } catch (TargetError) {
      continue
    }

    WinRestore(this_id)
    if (1 = WinGetminmax(this_id)) {
      minmax := -2
      WinRestore(this_id)
    }

    WinGetPos(&x, &y, &w, &h, this_id)
    winmap[this_id] := { x: x, y: y, w: w, h: h, minmax: minmax }
  }
}

restorewins(winmap) {
  for (this_id, d in winmap) {
    if (this_id = "mouse") {
      MouseMove(d.x, d.y, 0)
      continue
    }

    try {
      minmax := WinGetMinMax(this_id)
    } catch (TargetError) {
      continue
    }

    WinGetPos(&x, &y, , , this_id)
    if (d.x = x && d.y = y && d.minmax = minmax) {
      continue
    }

    WinMove(d.x, d.y, d.w, d.h, this_id)

    switch (d.minmax) {
      case (1): WinMaximize(this_id)
      case (-1): WinMinimize(this_id)
      case (-2):
        WinMaximize(this_id)
        WinMinimize(this_id)
    }
  }
}

2002|06|07|08|09|10|11|12|
2003|01|02|03|04|05|06|08|09|10|11|12|
2004|01|02|03|04|05|06|07|08|09|10|11|12|
2005|01|02|03|04|05|06|07|08|09|10|11|12|
2006|01|02|03|04|05|06|07|08|09|10|11|12|
2007|01|02|03|04|05|06|07|08|09|10|11|12|
2008|01|02|03|04|05|06|07|08|09|10|11|12|
2009|01|02|03|04|05|06|07|08|09|10|11|12|
2010|01|02|03|04|05|06|10|11|12|
2011|02|04|05|06|07|08|09|10|11|12|
2012|01|03|04|05|06|09|11|12|
2013|02|03|09|10|11|
2014|02|03|04|06|09|
2015|11|
2016|01|04|09|10|
2017|04|05|07|
2018|04|08|12|
2019|07|08|10|
2020|04|05|06|07|08|
2021|01|02|07|
2022|05|06|07|08|10|
2023|06|10|11|12|
2024|01|