#code=936T950
TEAM ENVI^ ENVIMODE=1| ENVI^ FORCELOCAL=1
SET  ::WM_DISPLAYCHANGE                =0x007E


IFEX OSK.LOG, LOGS * OSK.LOG
SET &NA_NFOCUS=-na
SET &I=1
FIND $%~1=-na, TEAM SET I=2| SET NA_NFOCUS=-na! FIND $%~1=-nfocus, TEAM SET I=2| SET NA_NFOCUS=-nfocus
SET &Dou=,
TEAM ENVI &Wide3=787| ENVI &High3=232| ENVI &Font_Size=9| ENVI &Font_Size1=| REGI #HKCU\Control Panel\Desktop\WindowMetrics\AppliedDPI,&Font_Size1| FIND $%&Font_Size1%=, ENVI &Font_Size1=96|
ENVI &Font_Cmd=IFEX %windir%\fonts\simsun*, ENVI @this.Font=%&Font_Size%:simsun! ENVI @this.Font=%&Font_Size%
ENVI &DPI=%&Font_Size1%/96
MSTR &&arg=<~%I%>%*
FIND $%arg%=-nxp, TEAM CALC I=%I% + 1| SET NA_NFOCUS=%NA_NFOCUS% -nxp
MSTR &&arg=<%I%->%*
CALL @WIN1 %arg%

_SUB WIN1,W%&Wide3%H%&High3%,软键盘,OnClose,,5,,-top -csize %NA_NFOCUS% -scalef -scale //-na //-nfocus //5改为#，变成无边框，无标题
    ENVI @this.POS=?:::::::::&WH:&CH
    %&Font_Cmd%
    TEAM SET &bCaps=0| SET &bLShift=0| SET &bRShift=0| SET &bShift=0| SET &bCtrl=0| SET &bRCtrl=0| SET &bLCtrl=0|SET &bWin=0
    TEAM SET &bAlt=0| SET &bRAlt=0| SET &bLAlt=0|SET &bWin=0| SET &bRWin=0| SET &bLWin=0| SET &bNum=0| SET &bScroll=0|SET &bPause=0
    ENVI @this.POS=::::::::::%&WH%:%CH%
    ENVI @this.POS=::::::::::%&WH%:%CH%
    PlaceIt
    TIME -t:1 ,10, PlaceIt
  
    ENVI @this.MSG=_%&::WM_DISPLAYCHANGE%:  ENVI @this.POS=::::::::::%&WH%:%CH%    //分辨率变化时执行 

    ITEM -b IESC,L1T7W30H24,Esc,SEND VK_ESCAPE,
    ITEM -b IF1,L75T7W30H24,F1,SEND VK_F1,
    ITEM -b IF2,L112T7W30H24,F2,SEND VK_F2,
    ITEM -b IF3,L149T7W30H24,F3,SEND VK_F3,
    ITEM -b IF4,L186T7W30H24,F4,SEND VK_F4,

    ITEM -b IF5,L233T7W30H24,F5,SEND VK_F5,
    ITEM -b IF6,L280T7W30H24,F6,SEND VK_F6,
    ITEM -b IF7,L317T7W30H24,F7,SEND VK_F7,
    ITEM -b IF8,L354T7W30H24,F8,SEND VK_F8,

    ITEM -b IF9,L389T7W30H24,F9,SEND VK_F9,
    ITEM -b IF10,L428T7W30H24,F10,SEND VK_F10,
    ITEM -b IF11,L465T7W30H24,F11,SEND VK_F11,
    ITEM -b IF12,L502T7W30H24,F12,SEND VK_F12,


    ITEM -b ITop,L1T42W30H30,`,XSENDSHIFT #0xC0,
    ITEM -b I1,L38T42W30H30,1, XSENDSHIFT 1,
    ITEM -b I2,L75T42W30H30,2,XSENDSHIFT 2,
    ITEM -b I3,L112T42W30H30,3,XSENDSHIFT 3,
    ITEM -b I4,L149T42W30H30,4,XSENDSHIFT 4,
    ITEM -b I5,L186T42W30H30,5,XSENDSHIFT 5,
    ITEM -b I6,L223T42W30H30,6,XSENDSHIFT 6,
    ITEM -b I7,L260T42W30H30,7,XSENDSHIFT 7,
    ITEM -b I8,L297T42W30H30,8,XSENDSHIFT 8,
    ITEM -b I9,L334T42W30H30,9,XSENDSHIFT 9,
    ITEM -b I0,L369T42W30H30,0,XSENDSHIFT 0,
    ITEM -b I_,L408T42W30H30,-,XSENDSHIFT -, //-21,
    ITEM -b IEQ,L445T42W30H30,=,XSENDSHIFT =, //-22,
    ITEM -b IEQ,L482T42W50H30,BackSpa,XSEND VK_BACK,


    ITEM -b ITAB,L1T79W40H30,Tab,XSEND #9,
    ITEM -b IQ,L57T79W30H30,q,XSENDSHIFT q,
    ITEM -b IW,L94T79W30H30,w,XSENDSHIFT w,
    ITEM -b IE,L131T79W30H30,e,XSENDSHIFT e,
    ITEM -b IR,L168T79W30H30,r,XSENDSHIFT r,
    ITEM -b IT,L205T79W30H30,t,XSENDSHIFT t,
    ITEM -b IY,L242T79W30H30,y,XSENDSHIFT y,
    ITEM -b IU,L279T79W30H30,u,XSENDSHIFT u,
    ITEM -b II,L316T79W30H30,i,XSENDSHIFT i,
    ITEM -b IO,L353T79W30H30,o,XSENDSHIFT o,
    ITEM -b IP,L390T79W30H30,p,XSENDSHIFT p,
    ITEM -b IML,L427T79W30H30,[,XSENDSHIFT [, //-21,
    ITEM -b IMR,L464T79W30H30,],XSENDSHIFT ],
    ITEM -b ISLASH,L502T79W30H30,\,XSENDSHIFT \,


    ITEM -b ICaps,L1T116W60H30,Caps,*PinPong ICaps bCaps  VK_CAPITAL VK_CAPITAL 1,
    ITEM -b IA,L75T116W30H30,a,XSENDSHIFT a,
    ITEM -b IS,L112T116W30H30,s,XSENDSHIFT s,
    ITEM -b ID,L149T116W30H30,d,XSENDSHIFT d,
    ITEM -b IF,L186T116W30H30,f,XSENDSHIFT f,
    ITEM -b IG,L223T116W30H30,g,XSENDSHIFT g,
    ITEM -b IH,L260T116W30H30,h,XSENDSHIFT h,
    ITEM -b IJ,L297T116W30H30,j,XSENDSHIFT j,
    ITEM -b IK,L334T116W30H30,k,XSENDSHIFT k,
    ITEM -b IL,L369T116W30H30,l,XSENDSHIFT l,
    ITEM -b IFen,L408T116W30H30,;,XSENDSHIFT #0xBA,
    ITEM -b IQU,L445T116W30H30,',XSENDSHIFT #222,
    ITEM -b IEN,L482T116W50H30,Ent,XSENDSHIFT #0xD,


    ITEM -b ILShift,L1T153W90H30,Shift,*PinPong ILShift bLShift VK_LSHIFT_  VK_LSHIFT^ 1,
    ITEM -b IZ,L94T153W30H30,z,XSENDSHIFT z,
    ITEM -b IX,L131T153W30H30,x,XSENDSHIFT x,
    ITEM -b IC,L168T153W30H30,c,XSENDSHIFT c,
    ITEM -b IV,L205T153W30H30,v,XSENDSHIFT v,
    ITEM -b IB,L242T153W30H30,b,XSENDSHIFT b,
    ITEM -b IN,L279T153W30H30,n,XSENDSHIFT n,
    ITEM -b IM,L316T153W30H30,m,XSENDSHIFT m,
    ITEM -b IDou,L353T153W30H30,%Dou%,XSENDSHIFT #0xBC,
    ITEM -b IDot,L390T153W30H30,.,XSENDSHIFT .,
    ITEM -b IAsk,L427T153W30H30,/,XSENDSHIFT ?,
    ITEM -b IRShift,L464T153W68H30,Shift,*PinPong IRShift bRShift VK_RSHIFT_  VK_RSHIFT^ 1,


    ITEM -b ILCtrl,L1T190W55H30,Ctrl,*PinPong ILCtrl bLCtrl VK_LCONTROL_  VK_LCONTROL^,
    ITEM -b ILWIN,L66T190W35H30,Win,*PinPong ILWIN bLWin VK_LWIN_  VK_LWIN^,
    ITEM -b ILALT,L108T190W35H30,Alt,*PinPong ILALT bLAlt VK_LMENU_  VK_LMENU^,
    ITEM -b ISPACE,L149T190W214H30,,XSEND VK_SPACE,
    ITEM -b IRALT,L369T190W35H30,Alt,*PinPong IRALT bRAlt VK_RMENU_  VK_RMENU^,
    ITEM -b IRWIN,L413T190W35H30,Win,*PinPong IRWIN bRWin VK_RWIN_  VK_RWIN^, //-21,
    ITEM -b IPRT,L455T190W35H30,Prt,SEND #0x11_%&Dou%P%&Dou%#0x11^,
    ITEM -b IRCtrl,L497T190W35H30,Ctrl,*PinPong IRCtrl bRCtrl VK_RCONTROL_  VK_RCONTROL^,

    ITEM -b IPrtSc,L541T42W30H30,PrtS,XSEND VK_SNAPSHOT, // -23,
    ITEM -b IScroll,L576T42W30H30,Scrl,*PinPong IScroll bScroll VK_SCROLL  VK_SCROLL,
    ITEM -b IPause,L611T42W30H30,Paus,*PinPong IPause bPause VK_PAUSE  VK_PAUSE,

    ITEM -b IInsert,L541T79W30H30,Ins,XSEND VK_INSERT,
    ITEM -b IHome,L576T79W30H30,Home, XSEND VK_HOME,
    ITEM -b IPageup,L611T79W30H30,PgUp,XSEND VK_PRIOR,

    ITEM -b IDelete,L541T116W30H30,Del,XSEND VK_DELETE,
    ITEM -b IEnd,L576T116W30H30,End, XSEND VK_END,
    ITEM -b IPageDown,L611T116W30H30,PgDn,XSEND VK_NEXT,

    ITEM -b IUp,L576T153W30H30,↑, XSEND VK_UP,

    ITEM -b ILeft,L541T190W30H30,←,XSEND VK_LEFT,
    ITEM -b IDown,L576T190W30H30,↓, XSEND VK_DOWN,
    ITEM -b IRight,L611T190W30H30,→,XSEND VK_RIGHT,



    ITEM -b INum,L650T42W30H30,Num,*PinPong INum bNum VK_NUMLOCK  VK_NUMLOCK 2, //-26,
    ITEM -b IPadSlash,L685T42W30H30,/,XSEND #0x6F,
    ITEM -b IPadMul,L720T42W30H30,*,XSEND #0x6A,
    ITEM -b IPadMin,L755T42W30H30,-,XSEND #0x6D,

    ITEM -b IPad7,L650T79W30H30,Home,XSENDPad VK_NUMPAD7 VK_HOME,
    ITEM -b IPad8,L685T79W30H30,↑,XSENDPad VK_NUMPAD8 VK_UP,
    ITEM -b IPad9,L720T79W30H30,PgUp,XSENDPad VK_NUMPAD8 VK_PRIOR,
    ITEM -b IPadAdd,L755T79W30H67,+,XSEND #0x6B,

    ITEM -b IPad4,L650T116W30H30,←,XSENDPad VK_NUMPAD4 VK_LEFT,
    ITEM -b IPad5,L685T116W30H30, ,XSENDPad VK_NUMPAD5 "",
    ITEM -b IPad6,L720T116W30H30,→,XSENDPad VK_NUMPAD6 VK_RIGHT,

    ITEM -b IPad1,L650T153W30H30,End,XSENDPad VK_NUMPAD1 VK_END,
    ITEM -b IPad2,L685T153W30H30,↓,XSENDPad VK_NUMPAD2 VK_DOWN,
    ITEM -b IPad3,L720T153W30H30,PgDn,XSENDPad VK_NUMPAD3 VK_NEXT,
    ITEM -b IPadEnter,L755T153W30H67,Ent,XSEND #0x0D,

    ITEM -b IPad0,L650T190W66H30,Ins, XSENDPad  VK_NUMPAD0 VK_INSERT,
    ITEM -b IPadDot,L720T190W30H30,Del,XSENDPad VK_DECIMAL VK_DELETE,


    ITEM -b IF1,L541T7W30H24,Mult,SEND #0xAD,
    ITEM -b IF2,L576T7W30H24,Vol-,SEND #0xAE, //-24,
    ITEM -b IF3,L611T7W30H24,Vol+,SEND #0xAF,
    ITEM -b IF4,L650T7W30H24,NoIn,SEND #0xAE,

    ITEM -b IF7,L685T7W30H24,▕←,SEND #0xB1, //-27,
    ITEM -b IF8,L720T7W30H24,→▍,SEND #0xB3, //→║,
    ITEM -b IF9,L755T7W30H24,→▏,SEND #0xB0,
//    ITEM -b IFLk,L237T244W30H24,Lock,SHUT K,

    CheckKey
    TIME  TK,1000, @CheckKey

    SET &bCaps0=%bCaps%
    SET &bNum0=%bNum%
    SET &bScroll0=%bScroll%
_END
_SUB PlaceIt
    SCRN -win &&W,&&H,&&x0,&&y0,&&p
    IFEX $[ %&WH%=%&Wide3% & %&CH%=%&High3% ], TEAM CALC &H=%&H%/(%&DPI%)| CALC #&H=%&H%|  //NT6系统，DPI:150%以上，屏幕实际高度比SCRN扫描出的高度要小，加上此条命令可防止软键盘在屏幕之外。
    ENVI @this.POS=?::@&w1:&&h1
    CALC #&&x=%x0% + (%W% - %w1%) / 2   
    CALC #&&y=%y0% + (%H% - %h1%)  
    FIND $%~1=-right,
    {*  CALC #&x=%x0% + (%W% - %w1%)  
        CALC #&y=%y0% + (%H% - %h1%) / 2 
    }
    FIND $%~1=-left,
    {*  CALC #&x=%x0% + 0  
        CALC #&y=%y0% + (%H% - %h1%) / 2  
    }
    FIND $%~1=-top,
    {*  CALC #&x=%x0% + (%W% - %w1%) / 2 
        CALC #&y=%y0% + 0
    }
    ENVI @this.POS=%&x%:%y%
_END

_SUB CheckKey
    @LOGS **ON=0
    @WAIT -scanall &V
    @FIND $%&V0%<>%&V%,
    {*  @TEAM SET &bCaps1=%bCaps%| SET &bNum1=%bNum%| SET &bScroll1=%bScroll%| SET &bPause1=%bPause%
        @TEAM MSTR  &Key=<21>%&V%|  CALC &bCaps= %&Key% & 1     //CAPLOCK 20+1//    低位是否亮(乒乓状态)
        @TEAM MSTR  &Key=<145>%&V%|  CALC &bNum= %&Key% & 1     //NUM 144+1//    低位是否亮(乒乓状态)
        @TEAM MSTR  &Key=<146>%&V%|  CALC &bScroll= %&Key% & 1  //ScrLOCK 145+1//    低位是否亮(乒乓状态)
        @TEAM MSTR  &Key=<20>%&V%|  CALC &bPause= %&Key% & 1    //PAUSE 19+1//    低位是否亮(乒乓状态)
        
        IFEX $%bCaps%<>%bCaps1%, UpdateCase
        IFEX $%bNum%<>%bNum1%, UpdateNum
        IFEX $%bCaps%<>%bCaps1%,!! IFEX $%bCaps%>0, ENVI @ICaps.bkcolor=0x80FF80!ENVI @ICaps.bkcolor=-1
        IFEX $%bNum%<>%bNum1%,!! IFEX $%bNum%>0, ENVI @INum.bkcolor=0x80FF80!ENVI @INum.bkcolor=-1
        IFEX $%bScroll%<>%bScroll1%,!! IFEX $%bScroll%>0, ENVI @IScroll.bkcolor=0x80FF80!ENVI @IScroll.bkcolor=-1
        IFEX $%bPause%<>%bPause1%,!! IFEX $%bPause%>0, ENVI @IPause.bkcolor=0x80FF80!ENVI @IPause.bkcolor=-1
    }
_END


_SUB OnClose
    ENVI @this.Visable=0
    IFEX $%&bLShift%>0, SEND VK_LSHIFT^
    IFEX $%&bRShift%>0, SEND VK_RSHIFT^
    IFEX $%&bLCtrl>0, SEND VK_LCONTROL^
    IFEX $%&bRCtrl%>0, SEND VK_RCONTROL^
    IFEX $%&bLAlt%>0, SEND VK_LMENU^
    IFEX $%&bRAlt%>0, SEND VK_RMENU^
    IFEX $%&bLWin%>0, SEND VK_LWIN^
    IFEX $%&bRWin%>0, SEND VK_RWIN^
    IFEX $%&bCaps%<>%bCaps0%, SEND VK_CAPITAL
    KILL \
_END



_SUB UpdateCase
    FIND $[ %bCaps%%bShift%=01 | %bCaps%%bShift%=10 ],
    {*  TEAM ENVI @IQ=Q| ENVI @IW=W| ENVI @IE=E| ENVI @IR=R| ENVI @IT=T| ENVI @IY=Y| ENVI @IU=U
        TEAM ENVI @II=I| ENVI @IO=O| ENVI @IP=P| ENVI @IA=A| ENVI @IS=S| ENVI @ID=D| ENVI @IE=F
        TEAM ENVI @IG=G| ENVI @IH=H| ENVI @IJ=J| ENVI @IK=K| ENVI @IL=L| ENVI @IZ=Z| ENVI @IX=X
        TEAM ENVI @IC=C| ENVI @IV=V| ENVI @IB=B| ENVI @IN=N| ENVI @IM=M
    }!
    {*  TEAM ENVI @IQ=q| ENVI @IW=w| ENVI @IE=e| ENVI @IR=r| ENVI @IT=t| ENVI @IY=y| ENVI @IU=u
        TEAM ENVI @II=i| ENVI @IO=o| ENVI @IP=p| ENVI @IA=a| ENVI @IS=s| ENVI @ID=d| ENVI @IE=f
        TEAM ENVI @IG=g| ENVI @IH=h| ENVI @IJ=j| ENVI @IK=k| ENVI @IL=l| ENVI @IZ=z| ENVI @IX=x
        TEAM ENVI @IC=c| ENVI @IV=v| ENVI @IB=b| ENVI @IN=n| ENVI @IM=m
    }
    IFEX $%bShift%>0,
    {*  TEAM ENVI @ITop=~| ENVI @I1=!| ENVI @I2=@| ENVI @I3=#| ENVI @I4=$| ENVI @I5=%| ENVI @I6=^
        TEAM ENVI @I7=&&| ENVI @I8=*| ENVI @I9=(| ENVI @I0=)| ENVI @I_=_| ENVI @IEQ=+| ENVI @ISLASH=|||
        TEAM ENVI @IFen=:| ENVI @IDou=<| ENVI @IDot=>| ENVI @IAsk=?|ENVI @IML={|ENVI @IMR=}| ENVI @IQU="
    }!
    {*  TEAM ENVI @ITop=`| ENVI @I1=1| ENVI @I2=2| ENVI @I3=3| ENVI @I4=4| ENVI @I5=5| ENVI @I6=6
        TEAM ENVI @I7=7| ENVI @I8=8| ENVI @I9=9| ENVI @I0=0| ENVI @I_=-| ENVI @IEQ==| ENVI @ISLASH=\
        TEAM ENVI @IFen=;| ENVI @IDou=,| ENVI @IDot=.| ENVI @IAsk=/|ENVI @IML=[|ENVI @IMR=]|  ENVI @IQU='
    }
    ENVI @this.InvalidateRect=::::1
_END

_SUB UpdateNum
    IFEX $%bNum%>0,
    {*  TEAM ENVI @IPad0=0| ENVI @IPad1=1| ENVI @IPad2=2| ENVI @IPad3=3| ENVI @IPad4=4| ENVI @IPad5=5
        TEAM ENVI @IPad6=6| ENVI @IPad7=7| ENVI @IPad8=8| ENVI @IPad9=9| ENVI @IPadDot=.
    }!
    {*  TEAM ENVI @IPad0=Ins| ENVI @IPad1=End| ENVI @IPad2=↓| ENVI @IPad3=PgDn| ENVI @IPad4=←| ENVI @IPad5=
        TEAM ENVI @IPad6=→| ENVI @IPad7=Home| ENVI @IPad8=↑| ENVI @IPad9=PgUp| ENVI @IPadDot=Del
    }
    ENVI @this.InvalidateRect=::::1
_END

//ICapsU bCaps  VK_CAPITAL,
_SUB PinPong 
    CALC &&bShift1=%bLShift% + %bRShift%
    SET &gnm=%1
    SET &vnm=%2
    SET~  &v=%vnm%
    --v[%&v%]
    CALC #v=1 - %&v%
    IFEX $%v%>0, ENVI @%gnm%.bkcolor=0x80FF80!ENVI @%gnm%.bkcolor=-1
    SET %vnm%=%v%
    IFEX $%v%>0, SEND  %~3!SEND  %~4
    CALC &&bShift2=%bLShift% + %bRShift%
    CALC &&bAlt2=%bLAlt% + %bRAlt%
    CALC &&bWin2=%bLWin% + %bRWin%
    IFEX $%bShift2%>%bShift1%, SET bShift=1! IFEX $%bShift2%<%bShift1%, SET bShift=0
    FIND $%~5=1,UpdateCase! FIND $%~5=2,UpdateNum
_END


_SUB XSEND 
    SEND %1
_END


_SUB XSENDSHIFT 
    SEND %1
    SET &upShift=0
    IFEX $%&bLShift%>0, TEAM SET bLShift=0| SET bShift=0| SET &upShift=1| ENVI @ILShift.bkcolor=-1| SEND VK_LSHIFT^
    IFEX $%&bRShift%>0, TEAM SET bRShift=0| SET bShift=0| SET &upShift=1| ENVI @IRShift.bkcolor=-1| SEND VK_RSHIFT^
    IFEX $%upShift%>0, UpdateCase
    IFEX $%&bLCtrl%>0, TEAM SET bLCtrl=0| ENVI @ILCtrl.bkcolor=-1| SEND VK_LCONTROL^
    IFEX $%&bRCtrl%>0, TEAM SET bRCtrl=0| ENVI @IRCtrl.bkcolor=-1| SEND VK_RCONTROL^
    IFEX $%&bLAlt%>0, TEAM SET bLAlt=0| ENVI @ILALT.bkcolor=-1| SEND VK_LMENU^
    IFEX $%&bRAlt%>0, TEAM SET bRAlt=0| ENVI @IRALT.bkcolor=-1| SEND VK_RMENU^
    IFEX $%&bLWin%>0, TEAM SET bLWin=0| ENVI @ILWIN.bkcolor=-1| SEND VK_LWIN^
    IFEX $%&bRWin%>0, TEAM SET bRWin=0| ENVI @IRWIN.bkcolor=-1| SEND VK_RWIN^
_END

_SUB XSENDPad 
    IFEX $%bNum%>0, SEND %~1!SEND %~2
_END


