AutoHotkey Community

It is currently May 26th, 2012, 10:40 pm

All times are UTC [ DST ]




Post new topic Reply to topic  [ 4 posts ] 
Author Message
PostPosted: September 14th, 2009, 10:48 pm 
Could somebody help me out a little please.
I have entered the code below and I only want to get the toggle text on the Tray Menu to read the ini file when it is first opened, but it always seems to revert back to the default (of ...on) and ignores the ini file.

Could somebody show me where i have gone wrong?


Code:
#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.
#SingleInstance force
#Persistent
SetTitleMatchMode, Slow
IniRead, t_MenuItemHide, C:\Hotkey.ini, Section, Key
;---------------------------------------------------------
; Names for the tray menu items:
t_MenuItemHide = Ignore Word On
t_MenuItemShow = Ignore Word Off
;---------------------------------------------------------
Menu, Tray, Add, %t_MenuItemHide%, t_ShowHide
Menu, Tray, Default, %t_MenuItemHide%
Menu, Tray, Add ;Separator
Menu, Tray, Add, Pause Script..., Pause
Menu, Tray, Add, Exit..., Exit
Menu, Tray, NoStandard

t_IsVisible = y
;---------------------------------------------------------
SetTimer, KeepAlive, 250
return
;---------------------------------------------------------
KeepAlive:
IfWinExist,Untitled - Notepad
{
WinActivate
  SendInput Add some text here
  Sleep, 400
WinWaitClose,Untitled - Notepad
}
else
if t_IsVisible = y
{
  ifWinExist, Document1 - Microsoft Word
    {
     WinActivate
     SendInput Add some pictures here
     WinWaitClose, Document1 - Microsoft Word
     }
}
Run, Calc.exe
Sleep, 1000
WinWaitClose, Calculator
return
;---------------------------------------------------------
t_ShowHide:
>^f11::
if t_IsVisible = y
{
   Menu, Tray, Rename, %t_MenuItemHide%, %t_MenuItemShow%
   t_IsVisible = n
   IniWrite, %t_MenuItemShow%, C:\Hotkey.ini,Section, Key
}
else
{
   Menu, Tray, Rename, %t_MenuItemShow%, %t_MenuItemHide%
   t_IsVisible = y
   IniWrite, %t_MenuItemShow%, C:\Hotkey.ini,Section, Key
}
return
;---------------------------------------------------------

Pause:
Pause
return

t_MenuExit:
Exit:
Msgbox, 4372, Warning , Are you sure you wish to Exit.
ifMsgBox, No   
return

ExitApp


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: September 14th, 2009, 10:53 pm 
Offline

Joined: August 14th, 2009, 2:40 pm
Posts: 237
Location: Finland
Just a wild guess here, I see you're using c:\file.ext as a location. In general, processes do not have access to that directory. try using %A_ScriptDir%\file.ext as the location of the inifile and see if that works?


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: September 14th, 2009, 11:05 pm 
Hi AnttiV

I only changed this file location for the forum as I thought everybody would have a c:\ drive.

It doesn't matter where it is, it just seems to ignore it.


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: September 14th, 2009, 11:54 pm 
Offline

Joined: August 14th, 2009, 2:40 pm
Posts: 237
Location: Finland
You first read t_MenuItemHide from the Inifile, then explicitly define it in the next line, so any value that gets read from the file is overwritten.

Code:
IniRead, t_MenuItemHide, C:\Hotkey.ini, Section, Key
;---------------------------------------------------------
; Names for the tray menu items:
t_MenuItemHide = Ignore Word On


Also, you Write t_MenuItemShow, but Read t_MenuItemHide? Is this the way it should be?

EDIT: Also, the F11 hotkey saves the same variable, regardless of any settings!

Code:
>^f11::
if t_IsVisible = y
{
   Menu, Tray, Rename, %t_MenuItemHide%, %t_MenuItemShow%
   t_IsVisible = n
   IniWrite, %t_MenuItemShow%, C:\Hotkey.ini,Section, Key
}
else
{
   Menu, Tray, Rename, %t_MenuItemShow%, %t_MenuItemHide%
   t_IsVisible = y
   IniWrite, %t_MenuItemShow%, C:\Hotkey.ini,Section, Key
}
return


EDIT3: Fingers quicker than brain, sorry :)

Anyways, you'd better of reading/writing the value of t_IsVisible, than the menuitems, as they are just the labels, and t_IsVisible is the variable that is checked.


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

All times are UTC [ DST ]


Who is online

Users browsing this forum: JSLover, Miguel, rbrtryn, XstatyK, Yahoo [Bot] and 56 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