屏幕键盘 v2.2 – feiyue

这是一个类似 Windows 屏幕键盘的小工具,写成函数形式,便于在开机脚本中使用。

 

/*
;------------------------------------
;  屏幕键盘 —— OSK() v2.2  By FeiYue
;
;  这是一个类似 Windows 屏幕键盘的小工具
;  写成函数形式,便于在开机脚本中使用
;------------------------------------
*/

OSK()

OSK(f="")
{
  static title, myid, arr, NewName, ShowOSK, LButtonDown, MouseIsOver
  ListLines, % (lls:=A_ListLines)?"Off":"Off"
  if (!title)
  {
    ; title:="屏幕键盘"
    title:="On-Screen Keyboard"
    NewName:={ "":"Space", Caps:"CapsLock"
      , App:"AppsKey", PrScn:"PrintScreen", ScrLk:"ScrollLock"
      , "↑":"Up", "↓":"Down", "←":"Left", "→":"Right" }
    ShowOSK:=Func(A_ThisFunc).Bind("")
    LButtonDown:=Func(A_ThisFunc).Bind("LButtonDown")
    MouseIsOver:=Func(A_ThisFunc).Bind("MouseIsOver")
  }
  if (f="MouseIsOver")
  {
    MouseGetPos,,, id
    return (id=myid and myid)
  }
  ListLines, %lls%
  if (f="HotkeyOn" or f="HotkeyOff")
  {
    f:=(f="HotkeyOn") ? "On":"Off"
    Hotkey, If, % MouseIsOver
    For k,v in StrSplit(",^,!,+,#,*", ",")
      Hotkey, $%v%LButton, %LButtonDown%, %f%
    Hotkey, If
    return
  }
  else if (f="LButtonDown")
  {
    Critical
    MouseGetPos,,, id, cid, 2
    if !(id=myid and myid)
      return
    if (cid="")
    {
      WinGetPos, wx, wy, ww,, ahk_id %myid%
      CoordMode, Mouse
      MouseGetPos, x1, y1
      ;------------------
      ListLines, % (lls:=A_ListLines)?"Off":"Off"
      timeout:=A_TickCount+3000
      State:=GetKeyState("LButton","P") "|" GetKeyState("LButton")
      While (A_TickCount<timeout)
      and (State=GetKeyState("LButton","P") "|" GetKeyState("LButton"))
        Sleep, 20
      ListLines, %lls%
      ;------------------
      if (x1>wx+ww-60 and x1<wx+ww and y1>wy and y1<wy+30)
      {
        %A_ThisFunc%("Close")
        return
      }
      MouseGetPos, x2, y2
      WinMove, ahk_id %myid%,, wx+x2-x1, wy+y2-y1
      return
    }
    ControlGetText, k,, ahk_id %cid%
    if k in Ctrl,Alt,Shift,Win
    {
      GuiControlGet, isEnabled, OSK: Enabled, % arr[k][1]
      For i,v in arr[k]
        GuiControl, OSK: Disable%isEnabled%, %v%
      if (isEnabled)
        return
      k:=(k="Win") ? "LWin" : k
    }
    s:=InStr(k," ") ? SubStr(k,0) : k
    s:=(v:=NewName[s]) ? v : s, s:="{" s "}"
    For i,k in StrSplit("Ctrl,Alt,Shift,Win", ",")
    {
      GuiControlGet, isEnabled, OSK: Enabled, % arr[k][1]
      if (!isEnabled)
      {
        For j,v in arr[k]
          GuiControl, OSK: Enable, %v%
        v:=(k="Win") ? "LWin" : k
        s={%v% Down}%s%{%v% Up}
      }
    }
    SendLevel, 10
    SendInput {Blind}%s%
    return
  }
  else if (f="Close")
  {
    Gui, OSK: Destroy
    %A_ThisFunc%("HotkeyOff"), myid:=""
    return
  }
  else if (f!="")
    return
  if (myid)
  {
    %A_ThisFunc%("Close")
    return
  }

  ; 键盘布局:[ 键名,宽度,间隔 ]
  ; Keyboard layout: [keyname, width, spacing]
  w1:=40, w2:=55, w3:=w1*14+2*13, arr:=[]

  s1:=[ ["Esc"],["F1",,w3-w1*13-15*2-2*9],["F2"],["F3"],["F4"],["F5",,15]
     ,["F6"],["F7"],["F8"],["F9",,15],["F10"],["F11"],["F12"]
     ,["PrScn",w2,10],["ScrLk",w2],["Pause",w2] ]

  s2:=[ ["~ ``"],["! 1"],["@ 2"],["# 3"],["$ 4"],["% 5"],["^ 6"]
     ,["&& 7"],["* 8"],["( 9"],[") 0"],["_ -"],["+ ="],["BS"]
     ,["Ins",w2,10],["Home",w2],["PgUp",w2] ]

  s3:=[ ["Tab"],["q"],["w"],["e"],["r"],["t"],["y"]
     ,["u"],["i"],["o"],["p"],["{ ["],["} ]"],["| \"]
     ,["Del",w2,10],["End",w2],["PgDn",w2] ]

  s4:=[ ["Caps",w2],["a"],["s"],["d"],["f"],["g"],["h"]
     ,["j"],["k"],["l"],[": `;"],[""" '"],["Enter",w3-w1*11-w2-2*12] ]

  s5:=[ ["Shift",w1*2],["z"],["x"],["c"],["v"],["b"]
     ,["n"],["m"],["< ,"],["> ."],["? /"],["Shift",w3-w1*12-2*11]
     ,["↑",w2,10+w2+2] ]

  s6:=[ ["Ctrl",w2],["Win",w2],["Alt",w2],["",w3-w2*7-2*7]
     ,["Alt",w2],["Win",w2],["App",w2],["Ctrl",w2]
     ,["←",w2,10],["↓",w2],["→",w2] ]

  ; 0x08000000  Click not to activate
  Gui, OSK: +AlwaysOnTop +Owner +E0x08000000 +Hwndmyid
  Gui, OSK: Font, s12, Verdana
  Gui, OSK: Margin, 10, 10
  Gui, OSK: Color, DDEEFF
  Loop, 6
  {
    if (A_Index<=2)
      j:=""
    For i,v in s%A_Index%
    {
      w:=(v.2 ? v.2 : w1), d:=(v.3 ? v.3 : 2)
      j:=(j="") ? "xm" : i=1 ? "xm y+2" : "x+" d
      Gui, OSK: Add, Button, %j% w%w% r0.8 -Wrap Hwndid, % k:=v.1
      if k in Ctrl,Alt,Shift,Win
        (!arr[k] && arr[k]:=[]), arr[k].Push(id)
    }
  }
  Gui, OSK: Show, NA, %title%
  %A_ThisFunc%("HotkeyOn")
  Try Menu, Tray, Delete, OSK
  Menu, Tray, Add, OSK, %ShowOSK%
  Menu, Tray, Default, OSK
  Menu, Tray, Click, 1
  For i,k in StrSplit("Ctrl,Alt,Shift,Win", ",")
  {
    SendInput {L%k% Up}
    SendInput {R%k% Up}
  }
  return
}

;

 

声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。

给TA捐赠
共{{data.count}}人
人已捐赠
其他教程

多进程共享对象-feiyue

2021-5-13 14:06:01

其他案例

语音数字-2.5-feiyue

2021-5-13 14:23:24

5 条回复 A文章作者 M管理员
  1. ccc

    路过收集哈哈

  2. YUMI

    看看 刚好需要这个

  3. Falcon

    谢谢大佬

  4. GreatMarx?

    谢谢大佬, 反馈个问题: 拖动窗口时,鼠标松开才移动而不是实时移动

  5. Jos

    感谢分享

个人中心
购物车
优惠劵
有新私信 私信列表
搜索