I should modify the framework to allow for this. I've gotten in the habit of checking the INI for the key, and if it's not there, only then do I add the default, which I've taken to storing in the XML. This means, if I add a new key, I don't blow away all the custom keys users have already re-defined. You can still use the Toolkit's HotkeyManager to do all the grunt work.

For example, my XML might contain the following:

<string id="Key01_Default">Alt-1</string>
<string id="Key01_Name">My Key 1</string>
<string id="Key01_Description">Does something neat</string>
<string id="Key02_Default">Alt-2</string>
<string id="Key02_Name">My Key 2</string>
<string id="Key02_Description">Does something neater</string>
<string id="Key03_Default">Alt-3</string>
<string id="Key03_Name">My Key 3</string>
<string id="Key03_Description">Does something neatest</string>

Then my register hotkey routine would contain something like:

For i = 1 to 3 ' Three is the total count of how many keys I'll be registering If Instr(INIFile(myINIFile).GetSectionKeys(HotkeyManager.INISectionName), "Key0" & i) <= 0 Then ' If it's not in the INI HotkeyManager.Add "Key0" & i, myStrings("Key0" & i & "_Default"), "HotkeyCallback" ' Add the default key
    End If
Set registeredHotkeys("Key0" & i) = Keyboard.RegisterHotkey(HotkeyManager.Key("Key0" & i), HotkeyManager.Data("Key0" & i), Nothing, i) ' Now register it.
Next

That adds each of my hotkeys, default or already defined, to a global registerHotkeys variable, which is just a Dictionary object. Each key is registered with the HotkeyCallback routine. My HotkeyCallback routine takes one parameter, and that's the key's identifier (that's i in the loop above). Then I can do something like:

Sub HotkeyCallback(hotkeyID)
    Select Case hotkeyID
        Case 1 ' My Key 1
            ' Do something for key 1
        Case 2 ' My Key 2
            ' Do something for key 2
        Case 3 ' My Key 3
            ' Do something for key 3
    End Select
End Sub

Hope that helps,

Aaron

On 2/12/2012 5:02 PM, Chip Orange wrote:
Hi Vic,

If you look at the register hotkeys subroutine generated by the WE Scripting
framework, you'll see a place where it tests for the number of hotkeys, and
if it's not what the program expects, then it writes all the hotkeys out
with their default settings.  I know you don't want to do this exactly, but,
you could modify this idea just slightly to get what you want.

First, you'd need to modify the number of hotkeys this section is looking
for to be 12 instead of 11; and you'll need to add a line for the newest
hotkey to be written along with it's default value to this portion of code.
Now, if it doesn't find 12 hotkeys it will write all twelve of them out to
the .ini file.

Now, make a copy of this portion, and insert it just before this code.  Set
it to test for the number of hotkeys equaling 11  instead of not equaling
12, and delete the lines which write out the first 11 hotkeys, leaving you
only the one line which writes out the newest one.  This way, for someone
with an .ini file which has only the original 11 defined, this code will add
the newest one with it's default value, bringing them up to 12.  For someone
who doesn't have any at all, they'll get all 12 written out new.

  hth,

Chip


-----Original Message-----
From: Vic Beckley [mailto:vic.beckl...@gmail.com]
Sent: Sunday, February 12, 2012 3:10 PM
To: GW Scripting List
Subject: Adding a new hotkey to an existing app

Hi all,

I have an app which has at present 11 hotkeys. I am wanting
to add at least one hotkey in addition to these. I really
don't want to delete the entire *.ini file because users
would lose any customizations they had made.

How can I test for the presence of key12 and add it if it
doesn't exist?

Jeff, I looked at your Winamp app but couldn't understand it.
It is too complicated for me and is way above my head.

Any help would be greatly appreciated. Thanks in advance.


Best regards from Ohio, U.S.A.,

Vic
E-mail: vic.beckl...@gmail.com



--
Aaron Smith
Web Development * App Development * Product Support Specialist
GW Micro, Inc. * 725 Airport North Office Park, Fort Wayne, IN 46825
260-489-3671 * gwmicro.com

To insure that you receive proper support, please include all past
correspondence (where applicable), and any relevant information
pertinent to your situation when submitting a problem report to the GW
Micro Technical Support Team.

Reply via email to