 |
AutoHotkey Community Let's help each other out
|
| View previous topic :: View next topic |
| Author |
Message |
MsgBox
Joined: 17 Nov 2005 Posts: 179 Location: Leicester, UK
|
Posted: Sat May 27, 2006 2:20 am Post subject: FKee3 |
|
|
Hello
This script is part of another script that I am working to replace Microsoft's "UnIntelliType Pro" for my Natural MultiMedia Keyboard.
I have used the scan codes for "my keyboard", so I hope that they are the same for all others????
I thought that I would post this part of it hare as it may be of use to someone else....maybe!?
Also, can someone with "more experience than me" (which will be most of you) tell me if my code is tidy and efficient?? ie. is what I have done set out correctly and could it have been written it with less code?
Any comments, idea's, thoughts etc will be very much appreciated.
EDIT - 28/05/06
Thanks to advice from one or two forum members, my code is now 100 lines lighter!!! ...and I'm a bit wiser. Thank you olfen and Laszlo
ADDED:-
Option to turn off/on "How-To" message box.
Option to choose your own editor.
Actions are now saved to a separate file from the script "FKee3Actions.txt" (see below). Good thinking TucknDar
EDIT - 05/06/06
Completely rewrote FKee3 using Laszlo's keypress counting script.
Changed FKee3Actions.txt to FKee3Actions.ahk (I like syntax highlighting)
ADDED:-
MODIFIER KEYS!! Two of them. Allowing a total of 96 actions compared to 24 with the old version.
Script automatically reloads when action file is updated.
Thanks.
| Code: | ;___________________
; \____FKee3_____/
; Coded by MsgBox. Last Edit:- 25/04/07
; Adds extra {F1}nctionality to your {F2}unction keys.
; With this script you can add two extra actions to an F-Key without using a Modifier.
; Using a Modifier adds another three actions per key.
; Two Modifier keys have been defined, "Win" and "Ctrl", giving a possable total of
; 96 actions on twelve keys. More can easily be added IF needed!
;
; How to use:-
; 1 key press = {default F-Key action}. With a Modifier {your action}.
; 2 key presses = {your action} ie. Send,^a^c
; 3 key presses = {your action} ie. Run, MyMostUsedPrograms.exe
;
; F1 is aready set up as a demonstration with AHK help (2nd key press) and a version
; (can't find the original) of Rajat's IntelliSence (3rd key press).
; Actions are defined in a separate file, " FKee3Actions.ahk "
; (which needs to be created manually on first use) in the script directory.
; If a key press is triggered that has not been assigned an action, you will
; be given the opportunity to do so. (Just press "Yes"). When FKee3Actions.ahk
; is saved, FKee3 will automatically reload.
#UseHook
#SingleInstance, force
SetTitleMatchMode, 2
SetTimer, UpdatedActions, 1000
; **Settings**********
FK3_ShowHowToMsg = 1 ; Show/hide "how-to" message box. 1=Show 0=Hide.
FK3_Editor = %Windir%\Notepad.exe ; Alternative action's editor?
; **Settings**********
Loop 12 { ; Defines hotkeys.
Hotkey F%A_Index%, FK3_Hoty
Hotkey #F%A_Index%, FK3_Hoty
Hotkey ^F%A_Index%, FK3_Hoty
}
Return
FK3_Hoty: ; Counts key presses.
If ( A_ThisHotKey = A_PriorHotKey and A_TimeSincePriorHotkey < 250 )
FK3_KeyPresses++
Else FK3_KeyPresses = 1
SetTimer FK3_KeyCheck, 275
Return
FK3_KeyCheck:
SetTimer FK3_KeyCheck, Off
If Asc(A_ThisHotkey) = Asc("F") and FK3_KeyPresses < 2 { ; Check first character of A_ThisHotkey for "F"...
Send, {%A_ThisHotkey%} ; ie. no Modifier, and 1 key press. Send {F1}...{F12}.
Return
}
IfGreater FK3_KeyPresses,3, SetEnv FK3_KeyPresses,3 ; If more than 3 key presses are detected, FK3_KeyPresses = 3.
If Asc(A_ThisHotkey) = Asc("#") ; Check A_ThisHotkey for Win Modifier.
StringReplace, Modi, A_ThisHotKey, #, Win- ; #FKey now = Win-FKey. For msgbox and action file.
Else
If Asc(A_ThisHotkey) = Asc("^") ; Check A_ThisHotkey for Ctrl Modifier.
StringReplace, Modi, A_ThisHotKey, ^, Ctrl- ; ^FKey now = Ctrl-FKey.
Else
Modi = %A_ThisHotKey% ; No modifier found.
Gosub %Modi%_%FK3_KeyPresses% ; Do action for pressed hotkey.
Return
#Include FKee3Actions.ahk ; Include external FKee3 action file.
FK3_MsgBoxSetup: ; If no action is defined for hotkey, show msgbox.
IfEqual, FK3_KeyPresses, 1, SetEnv, FK3_MsgPresses, One ; Set up text for msgbox.
IfEqual, FK3_KeyPresses, 2, SetEnv, FK3_MsgPresses, Two
IfEqual, FK3_KeyPresses, 3, SetEnv, FK3_MsgPresses, Three
Press = Presses
IfEqual, FK3_MsgPresses, One, SetEnv, Press, Press
MsgBox,4100, %A_ThisHotKey% :- %FK3_MsgPresses% Key %Press% , [ %Modi%_%FK3_KeyPresses% ]`nNo action has been defined for this hotkey yet.`nWould you like to open your editor and add one?
IfMsgBox yes ; If enabled, show how-to msgbox.
{
If FK3_ShowHowToMsg = 1
{
MsgBox,, Q - HOW DO I SET AN ACTION FOR [ %Modi%_%FK3_KeyPresses% ]?, [ %Modi%_%FK3_KeyPresses% ]`nYour editor (if defined in Settings) or notepad will open and go to the`ncorrect line in " FKee3Actions.ahk " for your hotkey.`nReplace " Gosub, FK3_MsgBoxSetup " with your code.`nSave file.`nFKee3 will automatically reload. Your new actions can then be used.`nThis MsgBox can (and probably should) be disabled. See Settings.
Gosub, FK3_EditActions
}
Else
Gosub, FK3_EditActions
}
Return
FK3_EditActions:
Run, %FK3_Editor% %A_WorkingDir%\FKee3Actions.ahk ; Start editor and load FKee3Actions.ahk
WinWaitActive, FKee3Actions.ahk
Send, ^{Home}^f%Modi%_%FK3_KeyPresses%{enter}{Home}{Down}+{End} ; Find and highlight correct line for the pressed hotkey.
Return
UpdatedActions: ; Reload script if FKee3Actions.ahk has changed.
FileGetAttrib, attribs, %A_ScriptDir%\FKee3Actions.ahk
IfInString, attribs, A
{
FileSetAttrib, -A, %A_ScriptDir%\FKee3Actions.ahk
SplashTextOn,250,50,FKee3:- Status,
(
FKee3Actions.ahk has changed. FKee3 will now RELOAD.
)
Sleep, 5000
Reload
}
Return |
This code needs to be saved to a file called "FKee3Actions.ahk" and saved in the script working dir. It will contain your actions and is needed for FKee3 to work. (It's a bit long!)
| Code: | ; Replace " Gosub, FK3_MsgBoxSetup " with your code.
; FKey_2 or 3 presses.
F1_2:
Run, %A_ProgramFiles%\AutoHotkey\AutoHotkey.chm ;Gosub, FK3_MsgBoxSetup
return
F1_3:
SetWinDelay 10
SetKeyDelay 0
AutoTrim, On
if A_OSType = WIN32_WINDOWS
Sleep, 500
C_ClipboardPrev = %clipboard%
clipboard =
Send, ^c
ClipWait, 0.1
if ErrorLevel <> 0
{
Send, {home}+{end}^c
ClipWait, 0.2
if ErrorLevel <> 0
{
clipboard = %C_ClipboardPrev%
return
}
}
C_Cmd = %clipboard%
clipboard = %C_ClipboardPrev%
Loop, parse, C_Cmd, %A_Space%`,
{
C_Cmd = %A_LoopField%
break
}
IfWinNotExist, AutoHotkey Help
{
RegRead, ahk_dir, HKEY_LOCAL_MACHINE, SOFTWARE\AutoHotkey, InstallDir
if ErrorLevel <> 0
{
ahk_dir = %ProgramFiles%\AutoHotkey
}
ahk_help_file = %ahk_dir%\AutoHotkey.chm
IfNotExist, %ahk_help_file%
{
MsgBox, Could not find the help file: %ahk_help_file%.
return
}
Run, %ahk_help_file%
WinWait, AutoHotkey Help
}
WinActivate
WinWaitActive
StringReplace, C_Cmd, C_Cmd, #, {#}
send, !n{home}+{end}%C_Cmd%{enter} ;Gosub, FK3_MsgBoxSetup
return
F2_2:
Gosub, FK3_MsgBoxSetup
return
F2_3:
Gosub, FK3_MsgBoxSetup
return
F3_2:
Gosub, FK3_MsgBoxSetup
return
F3_3:
Gosub, FK3_MsgBoxSetup
return
F4_2:
Gosub, FK3_MsgBoxSetup
return
F4_3:
Gosub, FK3_MsgBoxSetup
return
F5_2:
Gosub, FK3_MsgBoxSetup
return
F5_3:
Gosub, FK3_MsgBoxSetup
return
F6_2:
Gosub, FK3_MsgBoxSetup
return
F6_3:
Gosub, FK3_MsgBoxSetup
return
F7_2:
Gosub, FK3_MsgBoxSetup
return
F7_3:
Gosub, FK3_MsgBoxSetup
return
F8_2:
Gosub, FK3_MsgBoxSetup
return
F8_3:
Gosub, FK3_MsgBoxSetup
return
F9_2:
Gosub, FK3_MsgBoxSetup
return
F9_3:
Gosub, FK3_MsgBoxSetup
return
F10_2:
Gosub, FK3_MsgBoxSetup
return
F10_3:
Gosub, FK3_MsgBoxSetup
return
F11_2:
Gosub, FK3_MsgBoxSetup
return
F11_3:
Gosub, FK3_MsgBoxSetup
return
F12_2:
Gosub, FK3_MsgBoxSetup
return
F12_3:
Gosub, FK3_MsgBoxSetup
return
; Win-FKey_1,2 or 3 presses.
Win-F1_1:
Gosub, FK3_MsgBoxSetup
return
Win-F1_2:
Gosub, FK3_MsgBoxSetup
return
Win-F1_3:
Gosub, FK3_MsgBoxSetup
return
Win-F2_1:
Gosub, FK3_MsgBoxSetup
return
Win-F2_2:
Gosub, FK3_MsgBoxSetup
return
Win-F2_3:
Gosub, FK3_MsgBoxSetup
return
Win-F3_1:
Gosub, FK3_MsgBoxSetup
return
Win-F3_2:
Gosub, FK3_MsgBoxSetup
return
Win-F3_3:
Gosub, FK3_MsgBoxSetup
return
Win-F4_1:
Gosub, FK3_MsgBoxSetup
return
Win-F4_2:
Gosub, FK3_MsgBoxSetup
return
Win-F4_3:
Gosub, FK3_MsgBoxSetup
return
Win-F5_1:
Gosub, FK3_MsgBoxSetup
return
Win-F5_2:
Gosub, FK3_MsgBoxSetup
return
Win-F5_3:
Gosub, FK3_MsgBoxSetup
return
Win-F6_1:
Gosub, FK3_MsgBoxSetup
return
Win-F6_2:
Gosub, FK3_MsgBoxSetup
return
Win-F6_3:
Gosub, FK3_MsgBoxSetup
return
Win-F7_1:
Gosub, FK3_MsgBoxSetup
return
Win-F7_2:
Gosub, FK3_MsgBoxSetup
return
Win-F7_3:
Gosub, FK3_MsgBoxSetup
return
Win-F8_1:
Gosub, FK3_MsgBoxSetup
return
Win-F8_2:
Gosub, FK3_MsgBoxSetup
return
Win-F8_3:
Gosub, FK3_MsgBoxSetup
return
Win-F9_1:
Gosub, FK3_MsgBoxSetup
return
Win-F9_2:
Gosub, FK3_MsgBoxSetup
return
Win-F9_3:
Gosub, FK3_MsgBoxSetup
return
Win-F10_1:
Gosub, FK3_MsgBoxSetup
return
Win-F10_2:
Gosub, FK3_MsgBoxSetup
return
Win-F10_3:
Gosub, FK3_MsgBoxSetup
return
Win-F11_1:
Gosub, FK3_MsgBoxSetup
return
Win-F11_2:
Gosub, FK3_MsgBoxSetup
return
Win-F11_3:
Gosub, FK3_MsgBoxSetup
return
Win-F12_1:
Gosub, FK3_MsgBoxSetup
return
Win-F12_2:
Gosub, FK3_MsgBoxSetup
return
Win-F12_3:
Gosub, FK3_MsgBoxSetup
return
; Ctrl-FKey_1,2 or 3 presses.
Ctrl-F1_1:
Gosub, FK3_MsgBoxSetup
return
Ctrl-F1_2:
Gosub, FK3_MsgBoxSetup
return
Ctrl-F1_3:
Gosub, FK3_MsgBoxSetup
return
Ctrl-F2_1:
Gosub, FK3_MsgBoxSetup
return
Ctrl-F2_2:
Gosub, FK3_MsgBoxSetup
return
Ctrl-F2_3:
Gosub, FK3_MsgBoxSetup
return
Ctrl-F3_1:
Gosub, FK3_MsgBoxSetup
return
Ctrl-F3_2:
Gosub, FK3_MsgBoxSetup
return
Ctrl-F3_3:
Gosub, FK3_MsgBoxSetup
return
Ctrl-F4_1:
Gosub, FK3_MsgBoxSetup
return
Ctrl-F4_2:
Gosub, FK3_MsgBoxSetup
return
Ctrl-F4_3:
Gosub, FK3_MsgBoxSetup
return
Ctrl-F5_1:
Gosub, FK3_MsgBoxSetup
return
Ctrl-F5_2:
Gosub, FK3_MsgBoxSetup
return
Ctrl-F5_3:
Gosub, FK3_MsgBoxSetup
return
Ctrl-F6_1:
Gosub, FK3_MsgBoxSetup
return
Ctrl-F6_2:
Gosub, FK3_MsgBoxSetup
return
Ctrl-F6_3:
Gosub, FK3_MsgBoxSetup
return
Ctrl-F7_1:
Gosub, FK3_MsgBoxSetup
return
Ctrl-F7_2:
Gosub, FK3_MsgBoxSetup
return
Ctrl-F7_3:
Gosub, FK3_MsgBoxSetup
return
Ctrl-F8_1:
Gosub, FK3_MsgBoxSetup
return
Ctrl-F8_2:
Gosub, FK3_MsgBoxSetup
return
Ctrl-F8_3:
Gosub, FK3_MsgBoxSetup
return
Ctrl-F9_1:
Gosub, FK3_MsgBoxSetup
return
Ctrl-F9_2:
Gosub, FK3_MsgBoxSetup
return
Ctrl-F9_3:
Gosub, FK3_MsgBoxSetup
return
Ctrl-F10_1:
Gosub, FK3_MsgBoxSetup
return
Ctrl-F10_2:
Gosub, FK3_MsgBoxSetup
return
Ctrl-F10_3:
Gosub, FK3_MsgBoxSetup
return
Ctrl-F11_1:
Gosub, FK3_MsgBoxSetup
return
Ctrl-F11_2:
Gosub, FK3_MsgBoxSetup
return
Ctrl-F11_3:
Gosub, FK3_MsgBoxSetup
return
Ctrl-F12_1:
Gosub, FK3_MsgBoxSetup
return
Ctrl-F12_2:
Gosub, FK3_MsgBoxSetup
return
Ctrl-F12_3:
Gosub, FK3_MsgBoxSetup
return |
SlimlinE
Last edited by MsgBox on Wed Apr 25, 2007 12:31 am; edited 3 times in total |
|
| Back to top |
|
 |
TucknDar
Joined: 07 Jan 2006 Posts: 47 Location: Oslo, Norway
|
Posted: Sat May 27, 2006 9:41 am Post subject: |
|
|
I like it!!
I find that setting FK3_KeySpeed = 250 gives me enough time without annoying me, but I'll probably lower that more once I get used to FKee3. I can certainly see this script being in my startup-dir.
Great work! |
|
| Back to top |
|
 |
TucknDar
Joined: 07 Jan 2006 Posts: 47 Location: Oslo, Norway
|
Posted: Sat May 27, 2006 9:44 am Post subject: |
|
|
a little suggestion, as long as it doesn't delay the script (I'm a ahk-newb, so maybe it doesn't at all ): Maybe the Fkey-actions could be defined in a separate ini-file. If there is an update to the script, I'd probably accidentally overwrite my own definitions  |
|
| Back to top |
|
 |
MsgBox
Joined: 17 Nov 2005 Posts: 179 Location: Leicester, UK
|
Posted: Sat May 27, 2006 12:57 pm Post subject: |
|
|
Hello TucknDar
I'm glad you like it and thanks for taking the time to post a comment.
| Quote: | | I find that setting FK3_KeySpeed = 250 gives me enough time without annoying me, but I'll probably lower that more once I get used to FKee3. |
That setting is faster than mine (350) , you must have very good reflexes/accuracy.
| Quote: | | a little suggestion, as long as it doesn't delay the script (I'm a ahk-newb, so maybe it doesn't at all Embarassed ): Maybe the Fkey-actions could be defined in a separate ini-file. If there is an update to the script, I'd probably accidentally overwrite my own definitions Wink |
Thats a brilliant idea, I didn't think about losing definitions ...
except...
I haven't a clue how to do that yet!
I suppose homework will be to study iniwrite and iniread and (anyone)???
Thanks again TucknDar
SlimlinE
Last edited by MsgBox on Sun May 28, 2006 10:42 pm; edited 1 time in total |
|
| Back to top |
|
 |
TucknDar
Joined: 07 Jan 2006 Posts: 47 Location: Oslo, Norway
|
Posted: Sat May 27, 2006 2:04 pm Post subject: |
|
|
| SlimlinE wrote: |
| Quote: | | I find that setting FK3_KeySpeed = 250 gives me enough time without annoying me, but I'll probably lower that more once I get used to FKee3. |
That setting is faster than mine (350) , you must have very good reflexes/accuracy.  |
Heh, the trick you've provided with "rolling fingers", ie. press F-key once then quickly hit one or two random keys for action 2 and 3 works like a charm. With a bit of training this'll be great for increased efficiency!
| SlimlinE wrote: | | I suppose homework will be to study iniwrite and iniread and (anyone)??? |
hehe, yes, indeed. Whenever I see all of these really cool and helpful scripts I become increasingly aware of my own shortcomings... Hopefully I'll have some time to learn ahk-scripting soon. |
|
| Back to top |
|
 |
olfen
Joined: 04 Jun 2005 Posts: 99 Location: Stuttgart, Germany
|
Posted: Sat May 27, 2006 2:06 pm Post subject: |
|
|
Hello SlimlinE,
I haven't read your code in entirety, but I think there are some ways to write it more concisely, e.g. using functions and the One True Brace (OTB)-style.
Here's one example (untested):
| Code: |
Gosub, FK3_GetLable
FK3_KeyPressed = FK3_%FK3_KeyLable%
|
and
| Code: |
FK3_GetLable:
If A_ThisHotKey = SC03B
{
FK3_KeyLable = F1
Return
}
If A_ThisHotKey = SC03C
{
FK3_KeyLable = F2
Return
}
If A_ThisHotKey = SC03D
{
FK3_KeyLable = F3
Return
}
If A_ThisHotKey = SC03E
{
FK3_KeyLable = F4
Return
}
If A_ThisHotKey = SC03F
{
FK3_KeyLable = F5
Return
}
If A_ThisHotKey = SC040
{
FK3_KeyLable = F6
Return
}
If A_ThisHotKey = SC041
{
FK3_KeyLable = F7
Return
}
If A_ThisHotKey = SC042
{
FK3_KeyLable = F8
Return
}
If A_ThisHotKey = SC043
{
FK3_KeyLable = F9
Return
}
If A_ThisHotKey = SC044
{
FK3_KeyLable = F10
Return
}
If A_ThisHotKey = SC057
{
FK3_KeyLable = F11
Return
}
If A_ThisHotKey = SC058
{
FK3_KeyLable = F12
Return
}
Return
|
can be shortened to
| Code: |
FK3_KeyPressed := "FK3_" . FK3_GetLable()
|
and
| Code: |
FK3_GetLable() {
IfEqual, A_ThisHotKey, SC03B, return, "F1"
IfEqual, A_ThisHotKey, SC03C, return, "F2"
IfEqual, A_ThisHotKey, SC03D, return, "F3"
IfEqual, A_ThisHotKey, SC03E, return, "F4"
IfEqual, A_ThisHotKey, SC03F, return, "F5"
IfEqual, A_ThisHotKey, SC040, return, "F6"
IfEqual, A_ThisHotKey, SC041, return, "F7"
IfEqual, A_ThisHotKey, SC042, return, "F8"
IfEqual, A_ThisHotKey, SC043, return, "F9"
IfEqual, A_ThisHotKey, SC044, return, "F10"
IfEqual, A_ThisHotKey, SC057, return, "F11"
IfEqual, A_ThisHotKey, SC058, return, "F12"
}
|
Another example:
| Code: |
IF FK3_KeyPresses = 2
{
Gosub, FK3_MsgBoxSetup
}
|
can be replaced with:
| Code: |
IF FK3_KeyPresses = 2
Gosub, FK3_MsgBoxSetup
|
can be replaced with:
| Code: |
IfEqual, FK3_KeyPresses, 2, Gosub, FK3_MsgBoxSetup
|
|
|
| Back to top |
|
 |
Laszlo
Joined: 14 Feb 2005 Posts: 4016 Location: Pittsburgh
|
Posted: Sat May 27, 2006 6:17 pm Post subject: |
|
|
Nice idea! I will add something like this to my main script!
Here is a simplified skeleton of your script, without the actual functions. | Code: | #UseHook
Loop 12
Hotkey F%A_Index%, Hoty
Return
Hoty:
If ( A_ThisHotKey = A_PriorHotKey and A_TimeSincePriorHotkey < 250 )
count++
Else count = 1
SetTimer KeyCheck, 275
Return
KeyCheck:
SetTimer KeyCheck, Off
If (Count < 2) {
Send {%A_ThisHotKey%}
Return
}
IfGreater count,3, SetEnv count,3
GoTo %A_ThisHotKey%_%count%
F1_2: ; add below the labels your desired actions
F1_3:
F2_2:
F2_3:
F3_2:
F3_3:
F4_2:
F4_3:
F5_2:
F5_3:
F6_2:
F6_3:
F7_2:
F7_3:
F8_2:
F8_3:
F9_2:
F9_3:
F10_2:
F10_3:
F11_2:
F11_3:
F12_2:
F12_3:
MsgBox % A_ThisHotKey " --> " count
Return |
|
|
| Back to top |
|
 |
MsgBox
Joined: 17 Nov 2005 Posts: 179 Location: Leicester, UK
|
Posted: Sun May 28, 2006 10:41 pm Post subject: |
|
|
@ olfen
Thanks very much for taking the time to look over my code. Following your advice I have managed to reduce the size by nearly 100 lines! I must admit that I don't yet fully understand when and how to use functions. The manual says that you should consider using funcions rather than subroutines but ATM I remain virually clueless.
@ Laszlo
| Quote: | | Nice idea! I will add something like this to my main script! |
I'm glad that you like it and thank you too for your contribution.
Again, I don't fully understand what happens in your code but am slowly digesting it.
Could you (when you have some spare time) please explain how it works because can't see what triggers the hotkey. I've got an idea that it's got something to do with the loop,
| Code: | Loop 12
Hotkey F%A_Index%, Hoty
Return |
but I'm not clear about how that becomes the hotkey ie. does the loop run when the script is loaded and store the values or is it triggered when you first press an FKey or.....
Can I also ask, seeing as you seem to be very qualified and competent, is there a formula to follow that scripts writers use:
1- Know what you want to happen.
2- ...........................?
8- ...........................?
9- Test
etc
Your input on this point will be very much appreciated by me and I'm sure other novice ahkers? coders? scripters?
Thanks again Laszlo
| Quote: | | a little suggestion, as long as it doesn't delay the script (I'm a ahk-newb, so maybe it doesn't at all Embarassed ): Maybe the Fkey-actions could be defined in a separate ini-file. If there is an update to the script, I'd probably accidentally overwrite my own definitions Wink |
Following a suggestion by TucknDar, I looked into saving the actions in a separate file. After reading about saving and retrieving data from an ini file and a txt file, I settled for #Include-ing a txt file. Was that a good choice?
SlimlinE |
|
| Back to top |
|
 |
Laszlo
Joined: 14 Feb 2005 Posts: 4016 Location: Pittsburgh
|
Posted: Sun May 28, 2006 11:21 pm Post subject: |
|
|
The HotKey command defines hotkeys dynamically. "HotKey a, label" is the same as "a::GoSub label". In our case, a loop defines all 12 function keys as hotkeys, all with the same action: the Hoty subroutine. In this subroutine the A_ThisHotKey variable tells, what key activated it.
I don't think there is a universal formula for code writing. If I have an idea, I try it out with a simple prototype script, possibly each part separately. If they work, I put the code together, and test it in different situations. After the first few, I try to automate the tests, so I don't have to do that much work after each bug fix (usually I have more bugs than lines).
I had a friend, who thinks about the problem for days, building the code in his head. When he is ready, he writes it down. He does not need comments or indentation, the code is working the first time. (Once it did not. All of the colleagues came together. It was a big event. He looked at the code briefly, and said it was correct, the compiler has a bug. After two days of tests, he was proven right, there was a nasty bug in the compiler.) Anyway, he was a very good programmer, but almost useless for large projects: nobody could extend, modify his perfect code when requirements changed (they always do), not even him, it had to be re-written from scratch. |
|
| Back to top |
|
 |
corrupt
Joined: 29 Dec 2004 Posts: 2397
|
Posted: Mon May 29, 2006 12:12 am Post subject: |
|
|
| Laszlo wrote: | | If I have an idea, I try it out with a simple prototype script, possibly each part separately. If they work, I put the code together, and test it in different situations. After the first few, I try to automate the tests, so I don't have to do that much work after each bug fix (usually I have more bugs than lines). | I usually do the same. Most bugs I find are discovered almost the moment after I click "Submit" though... . |
|
| Back to top |
|
 |
MsgBox
Joined: 17 Nov 2005 Posts: 179 Location: Leicester, UK
|
Posted: Fri Jun 02, 2006 11:50 pm Post subject: |
|
|
@ Laszlo
Now that I've had time to study and digest your script, I now fully understand how it works. Thanks for clarifying the hotkey loop, I couldn't get my head round it, but all is clear now!
I've been playing around with it and have found that it is easily adaptable to use modifier keys
| Code: | Loop 12
Hotkey F%A_Index%, Hoty
Loop 12
Hotkey #F%A_Index%, Hoty
Loop 12
Hotkey ^F%A_Index%, Hoty
Return |
(in any combination), which extends the functionality of the keyboard no end. I will update the original script with yours and post it.... soon!
As I said at the top of this thread, I am replacing my keyboard software "MS IntelliType Pro" which has buttons only accesable by AHK using scan codes, so I don't think that I can use your script for that. My own attempt is working well (although, no modifier keys as yet) and I will be posting it in the near future.
| Quote: | | I don't think there is a universal formula for code writing. |
No magic formula then, though, your pointers have been noted.
Cheers. |
|
| Back to top |
|
 |
Laszlo
Joined: 14 Feb 2005 Posts: 4016 Location: Pittsburgh
|
Posted: Sat Jun 03, 2006 4:42 am Post subject: |
|
|
One loop is enough: | Code: | Loop 12 {
Hotkey F%A_Index%, Hoty
Hotkey #F%A_Index%, Hoty
Hotkey ^F%A_Index%, Hoty
}
Return | You will have difficulties with | Code: | | Send {%A_ThisHotKey%} | because the braces are in the wrong place. You could try stringreplace-ing F with {F, and put the closing brace to the end.
If you need scan codes, you can use in place of Loop 12 | Code: | keys= SC03B,SC03C,SC03D ;...
Loop Parse, keys, `,
HotKey %A_LoopField%, Hoty |
Last edited by Laszlo on Tue Jun 06, 2006 3:40 pm; edited 1 time in total |
|
| Back to top |
|
 |
MsgBox
Joined: 17 Nov 2005 Posts: 179 Location: Leicester, UK
|
Posted: Tue Jun 06, 2006 12:54 am Post subject: |
|
|
| Code: | Code:
Loop 12
Hotkey F%A_Index%, Hoty
Loop 12
Hotkey #F%A_Index%, Hoty
Loop 12
Hotkey ^F%A_Index%, Hoty
Return |
| Code: | One loop is enough:
Code:
Loop 12 {
Hotkey F%A_Index%, Hoty
Hotkey #F%A_Index%, Hoty
Hotkey ^F%A_Index%, Hoty
}
Return |
I know better now. Thanks.
| Quote: | You will have difficulties with
Code:
Send {%A_ThisHotKey%}
because the braces are in the wrong place. You could try stringreplace-ing F with {F, # with #{ and finally ^ with ^{, and put the closing brace to the end. |
I'm not sure what you mean by this. I never had that problem. ???
| Code: | If you need scan codes, you can use in place of Loop 12
Code:
keys= SC03B,SC03C,SC03D ;...
Loop Parse, keys, `,
HotKey %A_LoopField%, Hoty |
"Ahh!...so, thats how you do it!" was what I said when I read that. I didn't know where to start with that problem. I will have a play with it when I have the time. Thank you.
I have posted the updated version. |
|
| Back to top |
|
 |
Laszlo
Joined: 14 Feb 2005 Posts: 4016 Location: Pittsburgh
|
Posted: Tue Jun 06, 2006 3:37 pm Post subject: |
|
|
I meant that if you have Fn hotkeys with modifiers like *, ~ or $, you cannot just send %A_ThisHotKey%. You have to remove these modifiers. If you have some of !#^+, you need to put a brace around the key name following, like | Code: | F1::
^F1::
^+F1::
StringReplace key, A_ThisHotkey, F, {F
MsgBox Send %Key%}
Return | If you use scan codes, replace F with S. For a more general solution, see here. |
|
| Back to top |
|
 |
MsgBox
Joined: 17 Nov 2005 Posts: 179 Location: Leicester, UK
|
Posted: Tue Jun 06, 2006 11:35 pm Post subject: |
|
|
Thanks for clarifying.
You confused me because, the only keys that are "sent" are the FKeys with no modifiers and one keypress (default), the rest trigger the subroutines which contain the actions. I now assume that you were referring to my other script which will need some alteration of the hotkeys...if I decide to use modifiers at all. I don't know if you're familiar with my keyboard, but it has an "F-Lock" key that toggles between normal Fkeys and useful?? shortcuts, undo, redo, reply, fwd etc. which I hardly ever use. Actions can be attached to the keys in both states, so maybe adding modifier keys would be overkill. But..., if I did add them, would all the extra code in the actions file affect performance? Atm it contains about 400 lines.
Thanks again for all of your good info, it really is appreciated. |
|
| 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
|