AutoHotkey v2.0-a127版本的代码,用最新v2正式版需要修正代码

#Requires AutoHotkey v2.0-a127

class KeyboardHook {
  Ptr := 0, VK := 0, SC1 := 0, NFP := 0, KeyUp := 0
  __New(Event := unset) {
    if IsSet(Event)
      this.DefineMethod('OnEvent', Event)
  }
  __Delete() => (this.Stop(), true)
  Stop() {
    DllCall('UnhookWindowsHookEx', 'Ptr', this), CallbackFree(this.cb)
  }
  OnEvent(wParam, lParam) => false
  Start() {
    this.Ptr := DllCall('SetWindowsHookEx', 'Int', WH_KEYBOARD_LL := 13, 'Ptr', this.cb := CallbackCreate('LowLevelMouseProc', 'F'), 'Ptr', DllCall('GetModuleHandle', 'UInt', 0, 'Ptr'), 'UInt', 0, 'Ptr')

    LowLevelMouseProc(nCode, wParam, lParam) {
      this.VK := NumGet(lParam + 0, "UInt")
      Ext := NumGet(lParam + 0, 8, "UInt")
      this.SC1 := NumGet(lParam + 0, 4, "UInt")
      this.NFP := (Ext >> 4) & 1
      this.KeyUp := Ext >> 7
      return this.OnEvent(wParam, lParam) ? true : DllCall('CallNextHookEx', 'Ptr', 0, 'Int', nCode, 'UInt', wParam, 'UInt', lParam)
    }
  }
}
#Persistent
hk := KeyboardHook.New(Func('hookcallback'))
hk.Start()
hookcallback(self, wp, lp) {
  static altdown := false
  if (self.NFP)
    return false
  if (self.VK = 164 || self.VK = 165) {
    if (!altdown && self.KeyUp)
      Send('{LAlt Up}')
    altdown := !self.KeyUp
    return true
  } else if (altdown) {
    altdown := false
    Send('{LAlt Down}')
  }
}

 

声明:站内资源为整理优化好的代码上传分享与学习研究,如果是开源代码基本都会标明出处,方便大家扩展学习路径。请不要恶意搬运,破坏站长辛苦整理维护的劳动成果。本站为爱好者分享站点,所有内容不作为商业行为。如若本站上传内容侵犯了原著者的合法权益,请联系我们进行删除下架。