Jump to content
Sign in to follow this  

Recommended Posts

Hello,

I'm trying to write a hotkey program and I know exactly how to do it but it will be hard coded and the user won't be able to edit it.

HotKeySet("{ESC}", "HotKeyPressed")
HotKeySet("^!d", "HotKeyPressed")
HotKeySet("^+x", "HotKeyPressed")

While 1
    Sleep(500)
WEnd

Func HotKeyPressed()
    Switch @HotKeyPressed
        Case "{ESC}"
            Exit
        Case "^!d"
            ShellExecute("D:\Docs")
        Case "^+x"
            ShellExecute("D:\Docs\My Portables\Burner\AnyBurn\AnyBurn.exe")
    EndSwitch
EndFunc

I want the program to read a file that has hotkeys on odd lines and paths on even lines but I don't see how the program will load into itself.

Is it even possible?

Thanks.

Share this post


Link to post
Share on other sites

I know about the reading ini but let's say we read all the hotkeys and the paths that it has to execute. Now how do we generate a function on runtime and execute it? In he example above, that would be HotkeyPressed() function.

Share this post


Link to post
Share on other sites

sorry leomoon, i missed the point there.

looks like you can't pass arguments to a function you call from HotKeySet so i guess you'd need to be able to dynamically create the functions based on what you read off the file.

does this thread help any?

 

Share this post


Link to post
Share on other sites

The first way is to loop and create functions but hotkeyset needs the function created already:

$ini = @ScriptDir&"\hotkeys.ini"
Global $aHotkeys = IniReadSection($ini, "Hotkeys")
Global $i

For $i = 1 To $aHotkeys[0][0]
    HotKeySet($aHotkeys[$i][0], $i)
Next

While 1
    Sleep(500)
WEnd

For $i = 1 To $aHotkeys[0][0]
    Func Eval($i)&"()"
        ShellExecute($aHotkeys[$i][1])
    EndFunc
Next

The second way is to make one function with cases which is better cuz the hotkeyset already has the function ready. I just don't know how to create the cases with the array:

$ini = @ScriptDir&"\hotkeys.ini"
Global $aHotkeys = IniReadSection($ini, "Hotkeys")
Global $i

For $i = 1 To $aHotkeys[0][0]
    HotKeySet($aHotkeys[$i][0], "HotKeyPressed")
Next

While 1
    Sleep(500)
WEnd

Func HotKeyPressed()
    Switch @HotKeyPressed
        ;Loop through array and create cases
        Case Else
            ;do nothing
    EndSwitch
EndFunc

 

Share this post


Link to post
Share on other sites

Its a dead quiet day here so I've been mucking around with it

$aHotkeys = IniReadSection(@ScriptDir & "\test.ini", "Hotkeys")

For $i = 1 To $aHotkeys[0][0]
    HotKeySet($aHotkeys[$i][0],"HotKeyPressed")
Next

While 1
    Sleep(500)
WEnd

Func HotKeyPressed()
    for $x = 1 to UBound($aHotkeys)-1
        if @HotKeyPressed = $aHotkeys[$x][0] Then Execute($aHotkeys[$x][1])
    Next
EndFunc

and make a file called test.ini in the root of the program folder with contents:
 

[Hotkeys]
+!d=ShellExecute("D:\backup")
+!x=ShellExecute("D:\repo")

this works for me

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By Dan_555
      Hi, 
      i'v just uploaded my latest project: Simple Snippet Manager to the Downloads. area :

       

       The intended usage is to select a Snippet, and to copy it's contents into your favorite Editor.
          The Copy/Paste process happens over the (windows)Clipboard. 
          The previous clipboard content is not restored.
          There is a time limit of 60 seconds, in which the pasting of the text is allowed (starting when the App window gets inactive).  
          The Hotkey is reenabled, when the main Window is activated.
          
          This is a File/Folder based manager. 
          The App is configured to hold 4000 files and 400 folders with searching depth of 5 sub-folders.
          
          The root folder is freely selectable, but it  should be a Folder with writing permission.
          Please install the App in a folder with Writing permission, too. 
          This App only uses an .ini file to save it's configuration, which has to be in the same folder as the App.
          
      First configuration:
      1. Open the config Window.
      2. Enter the Language name, create or seek a root folder, enter an extension.
      3. Click on Set button.
      4. Click on the Exit button.
      The Language configuration is done, adding files or folders are needed:
       1. Select the language from the dropbox list, and click on Get Lang button.
      2a. Right Click on the root folder, chose New folder to add categories.
      2b. or chose New/Edit file to open the builtin text editor
       3. Paste or Write a snippet-code, enter a filename and save it.
       
       (Repeat the 3. as needed)
       
      Usage:
      Select a language, then click on Get Lang button.
      Choose a file with the left mouse button.
      Check if the code was loaded in the Textarea at the bottom.
      Switch to your Sourcecode editor, and press the Hotkey (default= Ctrl/Strg b) to copy and paste the text.
      There is a time limit of 60 seconds, after the main window gets inactive, in which the copy&pasting is allowed.
      Changelog:
      V1.02        (24.06.2020)
                  Addition: Undocumented ini setting: StartLoadLastUsedLanguage
                            Setting this to 1 (default value) will now reload the Last used language at start.
                            Last used language counts for the Language, selected with [Get Lang] button. The [Config] button will delete the last used language.
                            LastUsedLanguageNr, LastUsedLanguageName ini settings are used internaly for the above function.
                   Added version string to the main Window title.
      V1.01        (23.06.2020)
                  Bugfix    : Starting the App without the ini file now sets the correct starting Hotkey (Ctrl b)
                  Addition: Clipboard is saved, before pasting, and restored after pasting. (May work with text data only. p.s. untested!)
    • By Dan_555
      Simple Snippet Manager (AutoIt v3.3.14.5)
       The intended usage is to select a Snippet, and to copy it's contents into your favorite Editor.
          The Copy/Paste process happens over the (windows)Clipboard. 
          The previous clipboard content is not restored.
          There is a time limit of 60 seconds, in which the pasting of the text is allowed (starting when the App window gets inactive).  
          The Hotkey is reenabled, when the main Window is activated.
          
          This is a File/Folder based manager. 
          The App is configured to hold 4000 files and 400 folders with searching depth of 5 sub-folders.
          
          The root folder is freely selectable, but it  should be a Folder with writing permission.
          Please install the App in a folder with Writing permission, too. 
          This App only uses an .ini file to save it's configuration, which has to be in the same folder as the App.
          
      First configuration:
      1. Open the config Window.
      2. Enter the Language name, create or seek a root folder, enter an extension.
      3. Click on Set button.
      4. Click on the Exit button.
      The Language configuration is done, adding files or folders are needed:
       1. Select the language from the dropbox list, and click on Get Lang button.
      2a. Right Click on the root folder, chose New folder to add categories.
      2b. or chose New/Edit file to open the builtin text editor
       3. Paste or Write a snippet-code, enter a filename and save it.
       
       (Repeat the 3. as needed)
       
      Usage:
      Select a language, then click on Get Lang button.
      Choose a file with the left mouse button.
      Check if the code was loaded in the Textarea at the bottom.
      Switch to your sourcecode editor, and press the Hotkey (default= Ctrl/Strg b) to copy and paste the text.
      There is a timelimit of 60 seconds, after the main window gets inactive, in which the copy&pasting is allowed.
       
      The Download includes:
      32 + 64bit exe, sourcecode, icon, read me text and 2 Instructional Helpfiles in Html and PDF format.
    • By nacerbaaziz
      good morning autoit team
      please i need your help
      am trying to make an program that work with hotkeys
      it function is to change the volume to the current application
      e.g when i select the vlc window by using this hotkey i will be able to change the vlc volume with out changing the system volume.
       am able to get the process handle and the process name of the window
      but when am trying to get or set the volume i does not succeded
      i tried to search in this forums but no result.
      can you please guide me to do that.
      am waiting for your answers
      thanks in advanced
    • By Stormgrade
      Hello.
      I'm french, sorry for my english.
      I release my project, a password manager : Password Keeper
      First I would like to thanks Guinness and Melba23 for their help, and I'm very sorry for those I forget, please remind me to add you.
      Well my program manage and crypt passwords, first I understand if you don't trust me for this kind of sensible software, but I remember you that all the the source files are at your disposal, fell free to explore them.
      The login is : admin and you can change it later
      How it work ? see Methode de cryptage en BDD.pdf in french
      login

       
      The main interface
      You can obviously add,modify and delete your entry, also you can search with keywords

      A password generator is included

      I won't update it anymore.
      It's a BSD license.
      Autoit version : 3.3.14.5
      Have a good day.
      Methode de cryptage en BDD.pdf Passwordkeeper.7z
    • By Skeletor
      Hey All,
      Yes, this is an odd request. 
      But is there a way to bulk up the size of the compiled program? 
      I know many want to reduce it's size, but I want to increase it.
      What methods do you suggest?
×
×
  • Create New...