AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

how to create a key buffer

 
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Ask for Help
View previous topic :: View next topic  
Author Message
silkcom



Joined: 23 Jan 2008
Posts: 131

PostPosted: Wed Jul 02, 2008 5:05 pm    Post subject: how to create a key buffer Reply with quote

I'm looking to create a keyword launcher, I need some help.

I want to create a key buffer, i.e. if they type in 't' 'e' 's' 't' then I want the buffer to hold the word 'test', if however they type 't' 'e' [space] 's' 't', I want the buffer to hold the word 'st'. Space, clicking, backspace etc should clear the buffer and have it start again.

Does anyone know how to code this? (as a test it would be nice if the code also showed a constant tooltip of the current buffer if it's not empty)

thanks to anyone for help, I'll be sure to share the end project/code if I can ever get it working just right.
Back to top
View user's profile Send private message
SKAN



Joined: 26 Dec 2005
Posts: 6264

PostPosted: Wed Jul 02, 2008 5:33 pm    Post subject: Reply with quote

Not well-tested:

Code:
#SingleInstance,Force

Loop {
Input, C, L1 V1, {Return}
If ( C=" " ) {
               Word:=""
               Tooltip
             }     
Else
               Word .= C
Tooltip %Word%
}


Smile
_________________
Back to top
View user's profile Send private message
Razlin



Joined: 05 Nov 2007
Posts: 434
Location: canada

PostPosted: Wed Jul 02, 2008 5:34 pm    Post subject: Reply with quote

lookup

input and tooltip in help.

have your endkey be a space

that should get you going..

post other questions once you get going.
_________________
-=Raz=-
Back to top
View user's profile Send private message
silkcom



Joined: 23 Jan 2008
Posts: 131

PostPosted: Wed Jul 02, 2008 5:36 pm    Post subject: Reply with quote

Awesome, let me look at that. I'm sure i'll have tons of more questions.
Back to top
View user's profile Send private message
silkcom



Joined: 23 Jan 2008
Posts: 131

PostPosted: Wed Jul 02, 2008 5:46 pm    Post subject: Reply with quote

First off, that was EXACTLY what I asked for, and incredibly quick, thank you.

How would I have more than one end key? I want it to detect all keys, and do 1 of 2 things with each key: 1) clear the buffer (if it's not a letter), 2) add to the buffer.

I'd also like the ability to clear the buffer on mouse clicks.
Back to top
View user's profile Send private message
SKAN



Joined: 26 Dec 2005
Posts: 6264

PostPosted: Wed Jul 02, 2008 6:24 pm    Post subject: Reply with quote

silkcom wrote:
How would I have more than one end key? I want it to detect all keys, and do 1 of 2 things with each key: 1) clear the buffer (if it's not a letter), 2) add to the buffer.

I'd also like the ability to clear the buffer on mouse clicks.


Not well-tested:

Code:
Loop {
  Input, Key, L1 V, % "{LControl}{RControl}{LAlt}{RAlt}{LShift}{RShift}{LWin}{RWin}"
  . "{AppsKey}{F1}{F2}{F3}{F4}{F5}{F6}{F7}{F8}{F9}{F10}{F11}{F12}{Left}{Right}{Up}{Down}"
  . "{Home}{End}{PgUp}{PgDn}{Del}{Ins}{BS}{Capslock}{Numlock}{PrintScreen}{Pause}{Escape}"

  If ( Asc(Key) >= 65 && Asc(Key) <= 90 ) || ( Asc(Key) >= 97 && Asc(Key) <= 122 )
       Word .= Key
  Else Word := ""
  ToolTip %Word%
}

~LButton::
~MButton::
~RButton::
~XButton1::
~XButton2::
  Word := ""
  Tooltip
Return


Smile
_________________
Back to top
View user's profile Send private message
silkcom



Joined: 23 Jan 2008
Posts: 131

PostPosted: Wed Jul 02, 2008 7:19 pm    Post subject: Reply with quote

Ok, here's what I have so far. First problem:

I want it to be able to type in a keyword, the example here is 'ff'. Then if they hit tab I want it to launch the program. Easy enough, only problem is, that I want to send Tab if they ever hit tab without it being part of the keyword. Problem is that the way I have it, the tab becomes an infinite loop. Is there a way to fix this, or supress the tab and use ~Tab???


Code:

Loop {
  Input, Key, L1 V, % "{LControl}{RControl}{LAlt}{RAlt}{LShift}{RShift}{LWin}{RWin}"
  . "{AppsKey}{F1}{F2}{F3}{F4}{F5}{F6}{F7}{F8}{F9}{F10}{F11}{F12}{Left}{Right}{Up}{Down}"
  . "{Home}{End}{PgUp}{PgDn}{Del}{Ins}{BS}{Capslock}{Numlock}{PrintScreen}{Pause}{Escape}"

  If ( Asc(Key) >= 65 && Asc(Key) <= 90 ) || ( Asc(Key) >= 97 && Asc(Key) <= 122 )
       Word .= Key
  Else Word := ""
  if (Word = "ff")
  {
    ToolTip Firefox
  }
  else
  {
    ToolTip
  }
}

Tab::
  ;if they are hitting tab because they have a keyword, then we don't want
  ;the tab to be sent.
  if (Word = "ff")
  {
    Word := ""
    ToolTip
    run, Firefox
  }
  else
  {
    Send {Tab}    ;this creates an infinite loop
  }
Return

~LButton::
~MButton::
~RButton::
~XButton1::
~XButton2::
  Word := ""
  Tooltip
Return


thanks again for your help, hopefully you're starting to see what I eventually want to do by now Smile.
Back to top
View user's profile Send private message
SKAN



Joined: 26 Dec 2005
Posts: 6264

PostPosted: Wed Jul 02, 2008 7:34 pm    Post subject: Reply with quote

Code:
Loop {
  Input, Key, L1 V, % "{LControl}{RControl}{LAlt}{RAlt}{LShift}{RShift}{LWin}{RWin}"
  . "{AppsKey}{F1}{F2}{F3}{F4}{F5}{F6}{F7}{F8}{F9}{F10}{F11}{F12}{Left}{Right}{Up}{Down}"
  . "{Home}{End}{PgUp}{PgDn}{Del}{Ins}{BS}{Capslock}{Numlock}{PrintScreen}{Pause}{Escape}"

  If ( Asc(Key) >= 65 && Asc(Key) <= 90 ) || ( Asc(Key) >= 97 && Asc(Key) <= 122 )
       Word .= Key
  Else Word := ""
  ToolTip %Word%
}

~Tab::
  If IsLabel( Word )
     GoSub, %Word%
  Word := ""   
  ToolTip %Word%
Return

ff:
  Run, firefox.exe
Return

Calc:
  Run, Calc.exe
Return

Notepad:
  Run, notepad.exe
Return

~LButton::
~MButton::
~RButton::
~XButton1::
~XButton2::
  Word := ""
  Tooltip
Return


Smile
_________________
Back to top
View user's profile Send private message
silkcom



Joined: 23 Jan 2008
Posts: 131

PostPosted: Wed Jul 02, 2008 8:24 pm    Post subject: Reply with quote

Doesn't that still allow the Tab to be pressed? I want the tab to be ignored if it's part of a word. Also, for future reasons i've changed a little of what you have, i'll paste the code when it's all working to show you what I mean.
Back to top
View user's profile Send private message
silkcom



Joined: 23 Jan 2008
Posts: 131

PostPosted: Wed Jul 02, 2008 8:51 pm    Post subject: Reply with quote

Ok, here's my code thus far

So far, I'm able to do almost everything I wanted "version 1" to do.

It's easy to add more, and it's working well.

Things I still want for version 1
1: Tab needs to be suppressed
2: When they launch the program, the word should be removed from whereever it was typed
3: Store the keywords in a file

Version 2 will be the gui Smile.

Here's the code:

Code:

cnt := 0

;;;;;;;;;;;;;;;;;;;;;; EDIT THIS ;;;;;;;;;;;;;;;;;;;;;;;;;;;
;TYPES:  L = launch, W = website (eventually), S = shortcut
; tips = Tooltips that show up
;

abbrevs%cnt% := "ff"
tips%cnt% := "Firefox"
programs%cnt% := "Firefox"
types%cnt% := "L"
cnt := cnt + 1

abbrevs%cnt% := "gm"
tips%cnt% := "Gmail"
programs%cnt% := "http://gmail.google.com"
types%cnt% := "L"
cnt := cnt + 1

abbrevs%cnt% := "np"
tips%cnt% := "Notepad"
programs%cnt% := "Notepad"
types%cnt% := "L"
cnt := cnt + 1

abbrevs%cnt% := "sn"
tips%cnt% := "Syn Editor"
programs%cnt% := "c:\Program Files\syn\syn.exe"
types%cnt% := "L"
cnt := cnt + 1

;;;;;;;;;;;;;;;;;;;;;;;; STOP EDITTING ;;;;;;;;;;;;;;;;;;;;;;;;


Loop {
  Input, Key, L1 V, % "{LControl}{RControl}{LAlt}{RAlt}{LShift}{RShift}{LWin}{RWin}"
  . "{AppsKey}{F1}{F2}{F3}{F4}{F5}{F6}{F7}{F8}{F9}{F10}{F11}{F12}{Left}{Right}{Up}{Down}"
  . "{Home}{End}{PgUp}{PgDn}{Del}{Ins}{BS}{Capslock}{Numlock}{PrintScreen}{Pause}{Escape}"

  If ( Asc(Key) >= 65 && Asc(Key) <= 90 ) || ( Asc(Key) >= 97 && Asc(Key) <= 122 )
       Word .= Key
  Else Word := ""
  tipup := false
  Loop %cnt%
  {

    if (Word == abbrevs%A_index%)
    {
     tip := tips%A_index%
      ToolTip %tip%
      tipup := true
    }
    else
    {
     if (tipup == false)
        ToolTip
    }
  }
}

~Tab::
  Loop %cnt%
  {
    if (Word != "" && Word == abbrevs%A_index%)
    {
      Word := ""
       ToolTip
      program := programs%A_index%
      if (types%A_index% == "L")
      {
          run, %program%
      }
      else if (types%A_index% == "S")
      {
          Send %program%
      }

       return
    }
  }
Return

~LButton::
~MButton::
~RButton::
~XButton1::
~XButton2::
  Word := ""
  Tooltip
Return
Back to top
View user's profile Send private message
silkcom



Joined: 23 Jan 2008
Posts: 131

PostPosted: Wed Jul 02, 2008 9:55 pm    Post subject: Reply with quote

Ok, i fixed the file part,

Now I just need the Tab to be suppressed if used to launch a program, and for the letters to be removed (if I'm typing along and type ff{tab}, i want the ff to be removed). Then version 1 is done and I can start on the GUI.

thanks again for all your help (and for any help anyone else may give)

here's the new code:

Code:

Loop, read, keywords.ini
{
   LineNumber = %A_Index%
   Loop, parse, A_LoopReadLine, `,
    {
      types%LineNumber% := "L" ;default to Launch
      if (A_Index == 1)
         abbrevs%LineNumber% := A_LoopField
      else if (A_Index == 2)
         tips%LineNumber% := A_LoopField
      else if (A_Index == 3)
         programs%LineNumber% := A_LoopField
        else if (A_Index == 4)
         types%LineNumber% := A_LoopField
    }
   tosay := abbrevs%LineNumber%
}
cnt = %LineNumber%


Loop {
  Input, Key, L1 V, % "{LControl}{RControl}{LAlt}{RAlt}{LShift}{RShift}{LWin}{RWin}"
  . "{AppsKey}{F1}{F2}{F3}{F4}{F5}{F6}{F7}{F8}{F9}{F10}{F11}{F12}{Left}{Right}{Up}{Down}"
  . "{Home}{End}{PgUp}{PgDn}{Del}{Ins}{BS}{Capslock}{Numlock}{PrintScreen}{Pause}{Escape}"

  If ( Asc(Key) >= 65 && Asc(Key) <= 90 ) || ( Asc(Key) >= 97 && Asc(Key) <= 122 )
       Word .= Key
  Else Word := ""
  tipup := false
  Loop %cnt%
  {

    if (Word == abbrevs%A_index%)
    {
     tip := tips%A_index%
      ToolTip %tip%
      tipup := true
    }
    else
    {
     if (tipup == false)
        ToolTip
    }
  }
}

~Tab::
  Loop %cnt%
  {
    if (Word != "" && Word == abbrevs%A_index%)
    {
      Word := ""
       ToolTip
      program := programs%A_index%
      if (types%A_index% == "L")
      {
          run, %program%
      }
      else if (types%A_index% == "S")
      {
          Send %program%
      }

       return
    }
  }
Return

~LButton::
~MButton::
~RButton::
~XButton1::
~XButton2::
  Word := ""
  Tooltip
Return


and the keywords.ini file:
Code:

ff,Firefox,Firefox
gm,Gmail,http://gmail.google.com
np,Notepad,Notepad
sn,Syn Editor,c:\Program Files\syn\syn.exe
Back to top
View user's profile Send private message
silkcom



Joined: 23 Jan 2008
Posts: 131

PostPosted: Wed Jul 02, 2008 10:45 pm    Post subject: Version 1 Complete Reply with quote

Ok, here's version 1, let me know if you can think of any improvements:

Code:

Loop, read, keywords.ini
{
   LineNumber = %A_Index%
   Loop, parse, A_LoopReadLine, %A_Tab%
    {
      if (A_Index == 1)
         abbrevs%LineNumber% := A_LoopField
      else if (A_Index == 2)
         tips%LineNumber% := A_LoopField
      else if (A_Index == 3)
         programs%LineNumber% := A_LoopField
        else if (A_Index == 4)
         params%LineNumber% := A_LoopField
    }
   tosay := abbrevs%LineNumber%
}
cnt = %LineNumber%


Loop {
  Input, Key, L1 V, % "{LControl}{RControl}{LAlt}{RAlt}{LShift}{RShift}{LWin}{RWin}"
  . "{AppsKey}{F1}{F2}{F3}{F4}{F5}{F6}{F7}{F8}{F9}{F10}{F11}{F12}{Left}{Right}{Up}{Down}"
  . "{Home}{End}{PgUp}{PgDn}{Del}{Ins}{BS}{Capslock}{Numlock}{PrintScreen}{Pause}{Escape}"

  If ( Asc(Key) >= 65 && Asc(Key) <= 90 ) || ( Asc(Key) >= 97 && Asc(Key) <= 122 )
       Word .= Key
  Else Word := ""
  tipup := false
  Loop %cnt%
  {

    if (Word == abbrevs%A_index%)
    {
     tip := tips%A_index%
      ToolTip %tip%
      tipup := true
    }
    else
    {
     if (tipup == false)
        ToolTip
    }
  }
}

$Tab::
  Loop %cnt%
  {
    if (Word != "" && Word == abbrevs%A_index%)
    {
      Word := ""
      
      StringLen, len, abbrevs%A_index%
      Loop %len%
         Send {Backspace}
      
       ToolTip
      program := programs%A_index%
      param := params%A_index%
       run, %program%,%param%
       return
    }
  }
  Send {Tab}
Return

~LButton::
~MButton::
~RButton::
~XButton1::
~XButton2::
  Word := ""
  Tooltip
Return


and the ini
Code:

ff   Firefox   Firefox
gm   Gmail   http://gmail.google.com
np   Notepad   Notepad
sn   Syn Editor   c:\Program Files\syn\syn.exe
arp   Add/Remove Programs   c:\WINDOWS\system32\appwiz.cpl
cpkeyboard   Control Panel -- Keyboard   C:\WINDOWS\system32\main.cpl   @1
cpmouse   Control Panel -- mouse   C:\WINDOWS\system32\main.cpl
cpdisp   Desktop Display Settings   C:\WINDOWS\system32\desk.cpl   @0   3
ec   Eclipse   C:\eclipse\eclipse.exe
ap   Aptana   C:\Program Files\Aptana\Aptana Studio\AptanaStudio.exe
ie   Internet Explorer   IEXPLORER
exc   Microsoft Excel   excel
msw   Microsoft Word   Winword
mc   My Computer   "explorer.exe"   /e,::{20D04FE0-3AEA-1069-A2D8-08002B30309D}
cpnetwork   Network Connections   C:\WINDOWS\system32\ncpa.cpl
pnt   Paint   C:\WINDOWS\system32\mspaint.exe
cppower   Power Management Config   C:\WINDOWS\system32\powercfg.cpl


Notice that i've changed it so that rather than a type (which i may someday add), I have added parameters, so you can add parameters, as you see I needed in my current keywords.

If you find improvements let me know.

For some reason when you invoke the run command the amount of memory used makes a jump, kinda annoying, is that possible to clear out?
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Ask for Help All times are GMT
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group