Jump to content

ASCII-code-like hotkeys?


Recommended Posts

Hi, guys.

The short version of my question is:

Is there any way to create ASCII-code-like hotkeys?  I mean, to press a special key like CTRL or ALT or SHIFT, type two or three numpad keys, then release the special key and to launch a function that way?

The full story to bring you into the topic:

I created a little GUI that has several "category" tabs and each tab has got several buttons.  Each button launches a different program or "command".  And I would like to add the option to launch these same commands through hotkeys instead of clicking buttons.  So, I would like these hotkeys were something like:

ctrl + category number + button number = e.g. CTRL+11 or CTRL+011 (in numpad),

The challenge for me is that I can't use hotkeyset because I need to press two or three keys but not at the same time but in sequence.  The same way we oftenly use to type an ASCII code (press ALT, type two or three numpad keys and release ALT), I would like to press e.g. CTRL, and to be able to type two or three numpad keys before releaseing the special key. 

I've tried the format {CTRLDOWN}[NUMPAD1}[NUMPAD1}{CTRLUP} but I don't get it to work with hotkeyset.

Additional info:

My script's GUI is dynamical.  So, the number of tabs and buttons that it has got and the "commands" assigned to them are taken from an .ini file.  So, since I don't know the number of controls that I need to handle nor the function associated to them, the hotkeys need to be assigned dinamically as well.  That's why I thought in this "tab/button number" hotkey criteria.

Any suggestion about this?

Thanks for your help... :

Denik.

Edited by Denik
Link to comment
Share on other sites

I saw your post in the HotStrings topic here: '?do=embed' frameborder='0' data-embedContent>>

You're probably having problems with the keys not being registered or being registered incorrectly. You can add some debug info to the hotstring library to see which keys you are receiving.

Take the _HotString_GUIKeyProc method and replace it with:

Func _HotString_GUIKeyProc($hWnd, $Msg, $wParam, $lParam)
$aRet = DllCall('user32.dll', 'int', 'GetKeyNameText', 'int', $lParam, 'str', "", 'int', 256)
ConsoleWrite($aRet[0] & @CRLF)
ConsoleWrite($aRet[1] & @CRLF)
ConsoleWrite($aRet[2] & @CRLF)
;ConsoleWrite($aRet[3] & @CRLF) ; maybe add this one too, not sure how large this array was from memory
$sKeyName = $aRet[2]
If $sKeyName Then
_HotString_EvaluateKey($sKeyName)
EndIf
Return 0 ; dont run autoit internal handler, not sure what it is, but message = handled so do nothing
EndFunc
Link to comment
Share on other sites

Thanks for your help @Manadar.  In the meanwhile, I created my own hotkey with _isPressed this way:

; In this example if you press "{Ctrl}+01" a messagebox appears

#include <Misc.au3>

HotKeySet("{ESC}", "Terminate") ; press Esc to exit script

Func Terminate()
  Exit
EndFunc

Func RunCommand()
  MsgBox (0, "", "You pressed Ctrl+01")
EndFunc

Func MyHotKey()
   Local $hDLL = DllOpen("user32.dll")
      If _IsPressed("11", $hDLL) Then ; If Ctrl is pressed
         If _IsPressed("60", $hDLL) Then ; and then 0 is pressed...
            While _IsPressed("60", $hDLL)
               Sleep(100)
            WEnd ; ...and released
            While _IsPressed("11", $hDLL) ; and while Ctrl is still pressed...
               If _IsPressed("61", $hDLL) Then ; ...1 is pressed
                  While _IsPressed("11", $hDLL)
                     Sleep(100)
                  WEnd ; once Ctrl is released...
                  RunCommand() ; ...the RunCommand function is launched
               EndIf
            WEnd
         EndIf
      EndIf
      Sleep(100)
   DllClose($hDLL)
EndFunc

While 1
  MyHotKey()
WEnd

This is my first little contribution to the forum :dance:!!!

I'm not a developer so, obviously, all suggestions are welcome.

Denik

Edited by Denik
Link to comment
Share on other sites

Denik, you forgot a Sleep() in there when no keys are being pressed. The script maxes out one of my CPU cores.

 

Aha, it's true.  Thanks, Manadar.  I added it in the same script.

Edited by Denik
Link to comment
Share on other sites

  • 1 month later...

And this would be the same script working for any "{Ctrl}+xy" combination. "X" and "y" should be any numpad key.

; In this example if you press "{Ctrl}+xy" a messagebox appears.  "X" and "y" should be any numpad key.

#include <Misc.au3>

HotKeySet("{ESC}", "Terminate") ; press Esc to exit script

Func Terminate()
  Exit
EndFunc

Dim $c1, $c2
Dim $key1, $key2

Func RunCommand()
  MsgBox (0, "", "You pressed Ctrl+" & ($key1 - 60) & ($key2 - 60) & "")
EndFunc

Func MyHotKey()
   Local $hDLL = DllOpen("user32.dll")
      If _IsPressed("11", $hDLL) Then ; If Ctrl is pressed
         For $c1 = 60 To 69
            If _IsPressed($c1, $hDLL) Then ; and then first numpad key is pressed...
               $key1 = $c1
               While _IsPressed($c1, $hDLL)
                  Sleep(100)
               WEnd ; ...and released
               While _IsPressed("11", $hDLL) ; and while Ctrl is still pressed...
                  For $c2 = 60 To 69
                     If _IsPressed($c2, $hDLL) Then ; ...second numpad key is pressed
                        $key2 = $c2
                        While _IsPressed("11", $hDLL)
                           Sleep(100)
                        WEnd ; once Ctrl is released...
                        RunCommand() ; ...the RunCommand function is launched
                     EndIf
                  Next
                  $c2 = 60
               WEnd
            EndIf
         Next
         $c1 = 60
      EndIf
   Sleep(100)
   DllClose($hDLL)
EndFunc

While 1
  MyHotKey()
WEnd
Edited by Denik
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...