 |
AutoHotkey Community Let's help each other out
|
| View previous topic :: View next topic |
| Author |
Message |
silkcom
Joined: 23 Jan 2008 Posts: 131
|
Posted: Wed Jul 02, 2008 5:05 pm Post subject: how to create a key buffer |
|
|
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 |
|
 |
SKAN
Joined: 26 Dec 2005 Posts: 6264
|
Posted: Wed Jul 02, 2008 5:33 pm Post subject: |
|
|
Not well-tested:
| Code: | #SingleInstance,Force
Loop {
Input, C, L1 V1, {Return}
If ( C=" " ) {
Word:=""
Tooltip
}
Else
Word .= C
Tooltip %Word%
} |
 _________________
 |
|
| Back to top |
|
 |
Razlin
Joined: 05 Nov 2007 Posts: 434 Location: canada
|
Posted: Wed Jul 02, 2008 5:34 pm Post subject: |
|
|
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 |
|
 |
silkcom
Joined: 23 Jan 2008 Posts: 131
|
Posted: Wed Jul 02, 2008 5:36 pm Post subject: |
|
|
| Awesome, let me look at that. I'm sure i'll have tons of more questions. |
|
| Back to top |
|
 |
silkcom
Joined: 23 Jan 2008 Posts: 131
|
Posted: Wed Jul 02, 2008 5:46 pm Post subject: |
|
|
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 |
|
 |
SKAN
Joined: 26 Dec 2005 Posts: 6264
|
Posted: Wed Jul 02, 2008 6:24 pm Post subject: |
|
|
| 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 |
 _________________
 |
|
| Back to top |
|
 |
silkcom
Joined: 23 Jan 2008 Posts: 131
|
Posted: Wed Jul 02, 2008 7:19 pm Post subject: |
|
|
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 . |
|
| Back to top |
|
 |
SKAN
Joined: 26 Dec 2005 Posts: 6264
|
Posted: Wed Jul 02, 2008 7:34 pm Post subject: |
|
|
| 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 |
 _________________
 |
|
| Back to top |
|
 |
silkcom
Joined: 23 Jan 2008 Posts: 131
|
Posted: Wed Jul 02, 2008 8:24 pm Post subject: |
|
|
| 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 |
|
 |
silkcom
Joined: 23 Jan 2008 Posts: 131
|
Posted: Wed Jul 02, 2008 8:51 pm Post subject: |
|
|
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 .
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 |
|
 |
silkcom
Joined: 23 Jan 2008 Posts: 131
|
Posted: Wed Jul 02, 2008 9:55 pm Post subject: |
|
|
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 |
|
 |
silkcom
Joined: 23 Jan 2008 Posts: 131
|
Posted: Wed Jul 02, 2008 10:45 pm Post subject: Version 1 Complete |
|
|
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 |
|
 |
|
|
You can post new topics in this forum You can reply to topics in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|