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