Hotkey Problems, getting old

Get help with using AutoHotkey and its commands and hotkeys
gibenedek
Posts: 14
Joined: 20 Sep 2020, 19:51

Hotkey Problems, getting old

20 Sep 2020, 20:44

Hello All! I have been coding in AHK (my first coding program) for about a month now, its been a lot of fun and Ive done some pretty cool stuff that im proud of, even if I know it isnt that signifigant. My favorite this far bing downloading a 3xkey press script, and modding it to be much more efficient (It had a name, but still Ive been using morse instead...its on topic so i'll get to that) and Ive made a little program with input that ,upon pressing AHK+{+} (The AHK key is my repurposed capslock key, which is now Rctrl.) It asks what service ive just signed up for, the user/email, and the password, and then appends a text file to keep track of all my passwords (Cant have symbols, must have symbols, no consecutive or 3x repeating numbers, to long to short, CANT USE A PREVIOUS PASSWORD...its too hard to remember whats what after 20+ years of internet) Personally, I wouldnt partake, but I could see it selling for $5, only saying to put a value on it. I cant wait to AHK all my friends pc's. They dont computer well.

Tl;DR , skip here---> ANYWAY, ive had to rewrite my hotkey/main scripts which usually include them, and ive had to do it about 5 or so times. I usually end up with some weird error. Ive turned appskey and rwin into F14/15, tilde into google key (f13) and use all the function keys for programs (1=picture related, 2 = text related, etc. until 11/12 become copy/paste) and Im using Morse to 1 2 3 tap hotkey them all. (if not just the key, then the AHK key is held) and I have ctrl+function keys as the regular function for the record.

First I did standard hotkey stuff, last attempt was a beautiful chart using Alt special chars and labels to call all the real code from the bottom, that was after the include attempt got all weird on me. (cant include file(wrong directory stated)).

I keep getting, through one key or another, key 1 being pressed by key 2, which is also pressing key 2. Ive had Circle Dock popping up when quick links should, but not the other way around, when circle was set to 2x press and ql set to 1. For some reason, once, I had Lwin as a hotkey with lwin+space nullifying the cancellation effect of holding it down (you know what I mean by that, yes?) and for some ungodly reason, it made l ctrl do the function that lwin & Space was set to (being 5x tab. Destroyed some script many times)

I gave up on all that, now im using

Code: Select all





Hot:
if (%A_ThisHotkey%Key_presses > 0) ; SetTimer already started, so we log the keypress instead.
{
   %A_ThisHotkey%Key_presses += 1
    return
}                                                                                                                                                                   The Guts 
; Otherwise, this is the first press of a new series. Set count to 1 and start
; the timer:
%A_ThisHotkey%Key_presses := 1
SetTimer, %A_ThisHotkey%Key, -400 ; Wait for more presses within a 400 millisecond window.
return
    
F1:: goto hot
F2:: Goto Hot
F3:: Goto Hot

F1Key: ;{
if (%A_ThisHotkey%Key_presses = 1) ;The key was pressed once. 
 ;}   
msgbox 2 ;{
    else if (%A_ThisHotkey%Key_presses = 2) ; The key was pressed twice.
    ;}                                                                                                                                                          The Dirty Work
  msgbox 22 ;{
        else if (%A_ThisHotkey%Key_presses > 2)
            ;}
        msgbox 222;{
    
%A_ThisHotkey%_presses := 0
;}
reload
return

;======================================================<>


F2Key: ;{
.........                                                                                                                                                      .you get the idea


So notice the "reload" in there? For some reason it only works once, and then stops working with no error, unless I reload.

QUESTIONS!!

1) Is that reload gonna give my pc lag? Its gonna happen after EVERY hotkey, if all goes according to plan

2) I didnt realize gosub returns to its spot, which Im starting to think is what ruined my last script. However, I went and placed the appropriate returns and I still had issues. So I was thinking:

Code: Select all





Hotkey, %keyname%, labelfor said key

FOR EVERY KEY
---------------------------
under all that, the labels and guis and includes.



Like I said Ive had trouble with include, am I putting it in the wrong spot maybe? I put it wherever. It seems labels dont carry over with include too, sometimes. And I dunno how to Library. On that note:

How do I Library? How do I call a directory with include? I followed the help file and it didnt work. So labels cant be global? Can I use Functions to make hotkeys? Im still new to functions. I'd like to do that so I dont need include OR all my code in 1 script.

ULTIMATELY, I wanna know what the best way to make a hotkey script, either all in one script, or with each instance of a hotkey bring included from its own script, into once "main" script. Is there some protip amazing way to make that super easy and short? That 1st code I modded so the 1st part only has to be coded once, maybe something along the lines of that? Am I safe going with the Hotkey command? Keep in mind, almost every key will have 3x press. (maybe not the abc ones)

And for bonus, cause yalls seem awesome: How can I write a hotkey for a mod key, and be 100% certain its not gonna act all weird. My winkey and ctrl attempts are on/off/incorrectly executing all the time. I know you gotta do

MOD & whatever::
-then -
MOD::

then I usually do MOD::MOD
but...errors. at one point or anotherr. Luckly I copy most to start over.

Double Bonus: Nearly Every time I do something with the mouse, one of the used keys stop working normally. wtf. PLZ halp. I NEED my Mouse chording.

Sorry for the book. I'll be happy with any answer, but Ive looked all over the googles and the helps. I couldnt search here till now but I ficured if im signed up, to try asking. Im sorry if some of this is asked all the time. But I havent found the 100% answer yet so here goes. Thanks guys.
gibenedek
Posts: 14
Joined: 20 Sep 2020, 19:51

Re: Hotkey Problems, getting old

24 Sep 2020, 07:31

Anyone?? Did I format the post wrong? Or are there issues with my post/question? Ive been trying to fix things on my own, im not asking for hand-outs. But This is getting annoying being as its a simple hotkey issue. Plz halp!

And happy coding!
RubbeH
Posts: 44
Joined: 13 Jul 2020, 08:40

Re: Hotkey Problems, getting old

24 Sep 2020, 07:57

Just a thought, It'd be better to shorten your post a bit since it's now a wall of text which might discourage people from even reading your question.

I think its a greater chance of getting help if you were to shorten your post and only include your code, the issue, what its supposed to do, and what you've done to try to resolve it.

Good luck!
FanaticGuru
Posts: 1481
Joined: 30 Sep 2013, 22:25

Re: Hotkey Problems, getting old

24 Sep 2020, 14:04

gibenedek wrote:
24 Sep 2020, 07:31
Anyone?? Did I format the post wrong? Or are there issues with my post/question? Ive been trying to fix things on my own, im not asking for hand-outs. But This is getting annoying being as its a simple hotkey issue. Plz halp!

Not sure exactly what you are attempting to do but if you are wanting a template where you can do different things based on how many times different hotkeys are pressed within a time period, here is an example:

Code: Select all

Key := {}

F1::
F2::
F3::
	if !Key[A_ThisHotkey]
		Key[A_ThisHotkey] := 1
	else
		Key[A_ThisHotkey]++
	SetTimer, % "Key_" A_ThisHotkey, -400 
return

Key_F1:
	Switch Key["F1"]
	{
		Case 1:
			MsgBox F1 Pressed 1
		Case 2:
			MsgBox F1 Pressed 2
		Default:
			MsgBox F1 Pressed 3 or more
	}
	Key["F1"] := 0
return

Key_F2:
	Switch Key["F2"]
	{
		Case 1:
			MsgBox F2 Pressed 1
		Case 2:
			MsgBox F2 Pressed 2
		Default:
			MsgBox F2 Pressed 3 or more
	}
	Key["F2"] := 0
return

Key_F3:
	Switch Key["F3"]
	{
		Case 1:
			MsgBox F3 Pressed 1
		Case 2:
			MsgBox F3 Pressed 2
		Default:
			MsgBox F3 Pressed 3 or more
	}
	Key["F3"] := 0
return

FG
Hotkey Help - Help Dialog for Currently Running AHK Scripts

AHK Startup - Consolidate Multiply AHK Scripts with one Tray Icon

[Function] Timer - Create and Manage Timers

Return to “Ask For Help”

Who is online

Users browsing this forum: Google [Bot], methos237, teadrinker, yssharie, zvit and 25 guests