AutoHotkey Community

It is currently May 27th, 2012, 10:04 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 5 posts ] 
Author Message
PostPosted: June 5th, 2009, 11:10 pm 
Offline

Joined: February 7th, 2009, 11:28 pm
Posts: 384
I'm not sure if this script warrants posting anywhere, but it's useful for me, so maybe it'll be of use to someone else.

The idea is just to have a quick way to review notes, for example, I recently adopted one of the mouse gesture scripts, so I want to be able to see the gestures flash up on my screen with a press of a button.

Hotkey: ~Esc - pressed down for 0.6 sec, does not prevent it's other uses. After 0.6s it activates the accent (`) key to flip though notes. Releasing Esc deactivates the script.

Note: I chose the accent (`) key because it's right under Esc on my keyboard. I also used its SC value, which may vary from computer to computer, so anyone using this should just change it to whatever is convenient for them.

Requires a "QuickNotes" folder in script's directory (default) with notes (.txt files, etc.) in it to display quickly:

update: uses F1 now instead of ``

Code:
#NoEnv
#SingleInstance force
SendMode, Input
CoordMode, ToolTip, Screen
SetWorkingDir, %A_ScriptDir%\QuickNotes

~Esc::
KeyWait, Esc, T0.6  ;press Esc down for 0.6 sec to activate quick-notes, F1 to flip thru them
if errorlevel
{
   note:=1
   loop, *.*
      index.= A_LoopFileName . "`n"
   ToolTip, %index%, %A_ScreenWidth%, 0
   Hotkey, F1, readQuickNotes, On
   KeyWait, Esc
   ToolTip
   Hotkey, F1, readQuickNotes, Off
   loop, % index0
      index%A_Index%:=
   note:=0, content= index= index0= target=
}
Return

readQuickNotes:
StringSplit,index,index,`n
FileRead, content, % target:= index%note%
note:= note < index0 ? note+1 : 1
ToolTip, %content%, %A_ScreenWidth%, 0
Return


Question 1: Is there a command or an easy way to clear all variables at the end of a script?

Question 2: I wanted to use F1 as the temporary hotkey instead of accent (`), but help windows from other apps kept popping up. I couldn't figure out how to temporarily (while Esc down) block F1 output outside of the script?

To add: Change accent (`) hotkey to F1 (more ergonomic), and extend quick notes to jpgs (i'm think SplashScreens to display image notes e.g. screenshots in jpg...).

edit: added SendMode, Input and On after first Hotkey command.

_________________
Hardware: 1.8 GHz laptop with 4 GB ram, Windows XP/SP3
Software: Prevx, Privatefirewall, KeyScrambler.


Last edited by pajenn on June 8th, 2009, 10:11 pm, edited 1 time in total.

Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: June 7th, 2009, 10:06 am 
Offline

Joined: October 17th, 2006, 4:15 pm
Posts: 7503
Location: Australia
Answer 1: If you want the variables cleared between each press of the hotkey, I suggest moving the code into a function and using local variables. Otherwise, I'm not sure what you mean.

Answer 2: Using "F1" in place of "sc029" should be sufficient. If the hotkey fires but a help window still comes up, I'm not sure what could be the problem. If your keyboard has a function-lock feature (F-lock key), perhaps that is interfering. Logitech SetPoint and Microsoft IntelliType (used to control keyboard features like F-lock) can also cause complications.


Btw, 'U' is not a valid option for KeyWait - "wait for key-up" behaviour is implied by the absence of 'D':
Code:
KeyWait, Esc, U

Also, `` (double back-quote) will work in place of sc029:
Code:
Hotkey, ``, readQuickNotes, On
Backquote is AutoHotkey's (default) escape character, so in this context `` means one literal `. Although the scancode of backquote may vary on different keyboard layouts, so would the key's physical location and suitability as a hotkey. I'd use `` merely because it saves having to explain sc029 in the comments. :)


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: June 8th, 2009, 10:25 pm 
Offline

Joined: February 7th, 2009, 11:28 pm
Posts: 384
Thanks for the response. I removed the U from KeyWait and replaced ` (sc029) with F1. It seems to work now without triggering its other functions.

Lexikos wrote:
Answer 1: If you want the variables cleared between each press of the hotkey, I suggest moving the code into a function and using local variables. Otherwise, I'm not sure what you mean.


I mean in general (not just for this script). The help file for FileRead says this:

Code:
FileRead, Contents, C:\Address List.txt
if not ErrorLevel  ; Successfully loaded.
{
    Sort, Contents
    FileDelete, C:\Address List (alphabetical).txt
    FileAppend, %Contents%, C:\Address List (alphabetical).txt
    Contents =  ; Free the memory.
}


So as a rule of thumb I try to clear all the variables at end of my persistent scripts to free the memory, but also to eliminate the type of interference that leftover values sometimes cause on later executions of the hotkey. However, I don't like writing var1= , var2= , var3= , ... so I'm asking if there's a 'ClearAll'-type command in AHK, or what AHK users use in place of it?

_________________
Hardware: 1.8 GHz laptop with 4 GB ram, Windows XP/SP3
Software: Prevx, Privatefirewall, KeyScrambler.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: June 8th, 2009, 10:33 pm 
Offline

Joined: May 27th, 2007, 9:41 am
Posts: 4999
pajenn wrote:
... a 'ClearAll'-type command in AHK, or what AHK users use in place of it?
AFAIK there is no such command, you can not
even check if a var is exist without "creating" one (I hope I describe
that correctly, I saw a post in the help recently).
Useful perhaps: VarExist()
http://www.autohotkey.com/forum/viewtop ... 3371#83371

_________________
AHK FAQ
TF : Text files & strings lib, TF Forum


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: June 8th, 2009, 11:07 pm 
Offline

Joined: October 17th, 2006, 4:15 pm
Posts: 7503
Location: Australia
Quote:
I mean in general (not just for this script).
Functions can be used in general...
Code:
SortAddressList()

SortAddressList()
{
    FileRead, Contents, C:\Address List.txt
    if not ErrorLevel  ; Successfully loaded.
    {
        Sort, Contents
        FileDelete, C:\Address List (alphabetical).txt
        FileAppend, %Contents%, C:\Address List (alphabetical).txt
    }
}
All local variables are freed automatically when the function returns/completes.


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: Bing [Bot] and 21 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group