Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

Crazy Scripting : Secret Numeric Labels


  • Please log in to reply
1 reply to this topic
SKAN
  • Administrators
  • 9115 posts
  • Last active:
  • Joined: 26 Dec 2005
Posted Image
SendMode Input

NumpadMult::
  Tc:=A_TickCount
  LongP=0
  Loop {
         Sleep 10
         NPdown:=GetKeyState("NumpadMult","P")
         IfEqual,NPDown,0, Break
         If ((A_TickCount-Tc)>499) {
         LongP=1
         Break
       }                           }
IfEqual,LongP,1,GoSub,CreateGUI
  Else
SendRaw *
Return

CreateGUI:
 Gui +AlwaysOnTop +ToolWindow -SysMenu
 Gui, Font, S14 Bold, Verdana
 Gui,Add,Listview, x5 y16 h33 +ReadOnly  w190 Center
 Gui,Add,Text    , x5 y16 h33 vSecretKey w190 Center
 Gui,Show, w200 h50, Enter Secret Numeric Label:
 LoopExit=0
 KeyLabel=

 Loop {
        IfEqual,LoopExit,1,Return
        vKey:=InputKey(2000)

        If (VKey>=0x30 AND VKey<=0x39 OR VKey>=0x60 AND VKey<=0x69) {
        StringRight,Num,Vkey,1
        KeyLabel=%KeyLabel%%Num%
        Mask:= StrLen(KeyLabel)
        Star=
        Loop, %Mask%
              Star=%Star%*
        GuiControl,,SecretKey,% Star
        }

        If (KeyLabel="" AND vKey="") {
        Gui, Destroy
        LoopExit=1
        }

        If (KeyLabel!="" AND (vKey="" OR vKey="0x0D")) {
        Gui, Destroy
        LoopExit=1
        if (IsLabel(KeyLabel))
           GoSub, %KeyLabel%
      } }
Return

InputKey(Duration=0, Prefix="")    {
 Global A_KBI_Timeleft
 IfEqual,Prefix,, SetEnv,Prefix,0x
 A_FI:=A_FormatInteger
 TC:=A_TickCount
 VarSetCapacity(lpKeyState,256,0)   
 DllCall("SetKeyboardState", UInt,&lpKeyState)
 Loop {
        DllCall("GetKeyboardState", UInt,&lpKeyState)
        Loop, 256 {
                    Int:=*(&lpkeystate+(A_Index-1))
                    If (Int>=0x80)
                      {
                        VK_CODE:=A_Index-1     
                        Break
                      }
                  }
        IfNotEqual,VK_CODE,, Break
        A_KBI_Timeleft:=Round((Duration-(A_TickCount-TC))/1000)
        If (Duration AND (A_TickCount-TC>=Duration))
           Break
        Sleep 20
      }
IfEqual,VK_CODE,, Return, VK_CODE
 SetFormat, Integer, Hex
 VK_CODE+=0
 StringReplace, VK_CODE, VK_CODE, 0x, 0x0
 StringRight, VK_CODE, VK_CODE, 2
 StringUpper, VK_CODE, VK_CODE
 SetFormat, Integer, %A_FI%
Retval=%Prefix%%VK_CODE%
Return RetVal
}

;-- Your Labels start from here

1111:
Run, Notepad.exe
Return

12345:
Run, Calc.exe
Return

Just a demonstration for my InputKey() function!

Run the above code.
Keep pressing Numeric pad Asterisk ( * ) for half-a-second and you will be prompted with a GUI where you can
enter a Numeric label.
1111 will start Notepad.exe & 12345 will start Calc.exe
You may press enter after entering a Numeric label or allow it to timeout!
Timeout is just 2 seconds .. Like in Indian Telephones :D
You will have to be quick enough ..
Append more labels as you like ( the label names have to be fully numbers .. and ofcourse unique! )

This will work out to be an utility if you want to load some file for which you do not want to have a shortcut.
I have many! ;)

More info on InputKey() : TipsNTricks: How to Capture Virtual-key code of a Keypress ?

Regards, :)
kWo4Lk1.png

Chris
  • Administrators
  • 10727 posts
  • Last active:
  • Joined: 02 Mar 2004
Nice. It might be slightly improved if you give a brief summary at the top so that casual readers can get an idea of what it does without having to read the entire post.