Page 1 of 1

Simple memory of lastpress

Posted: 16 Aug 2022, 08:37
by blad4
Using numbers via Numpad, i.e.

Code: Select all

"Numpad1"
for 1,

Code: Select all

"Numpad5"
for 5,

Code: Select all

"Numpad1 & Numpad3"
for 13

What is the simplest way to

Code: Select all

Numpaddot::
Send "last sent Numpad command"

Re: Simple memory of lastpress

Posted: 16 Aug 2022, 08:55
by Rohwedder
Hallo,
Numpad1:: for 1 and
Numpad1 & Numpad3:: for 13 ?
Show the Numpad command lines of your script.

Re: Simple memory of lastpress

Posted: 16 Aug 2022, 08:58
by blad4

Code: Select all

Numpad1::
ch=1
gosub sendroutine
return

Numpad2::
ch=9
gosub sendroutine
return

...


Numpad1 & Numpad2::
ch=122
gosub sendroutine
return

Numpad1 & Numpad3::
ch=137
gosub sendroutine
return

etc...



Re: Simple memory of lastpress

Posted: 16 Aug 2022, 09:09
by Rohwedder
Try:

Code: Select all

last_sent_Numpad_command  = Numpaddot
Numpad1::
ch=1
gosub sendroutine
return

Numpad2::
ch=9
gosub sendroutine
return

; ...


Numpad1 & Numpad2::
ch=122
gosub sendroutine
return

Numpad1 & Numpad3::
ch=137
gosub sendroutine
return

Numpaddot::
IF (last_sent_Numpad_command <> A_ThisHotkey)
	Goto, %last_sent_Numpad_command%
Return

sendroutine:
IF InStr(A_ThisHotkey, "Numpad")
	last_sent_Numpad_command := A_ThisHotkey
SoundBeep, 4000, 20
ToolTip,% ch
;...
Return

Re: Simple memory of lastpress

Posted: 16 Aug 2022, 09:15
by gregster
Didn't run it yet, but aren't parentheses missing here ? (Or percent symbols on the right side of the operator?)

Code: Select all

IF last_sent_Numpad_command <> A_ThisHotkey

Re: Simple memory of lastpress

Posted: 16 Aug 2022, 09:20
by Rohwedder
Yes, parentheses were missing.

Re: Simple memory of lastpress

Posted: 17 Aug 2022, 19:32
by blad4
Thank you Rohwedder, but I'm so baffled. In practice it keeps adding +1 to ch??

I'm obviously using

Code: Select all

 IF InStr 
completely wrong!!

Here is my routine:

Code: Select all

sendroutine:
if ch between 0 and 8
{
IF InStr(A_ThisHotkey, "Numpad")
	last_sent_Numpad_command := A_ThisHotkey
send ^g
send %ch%
send {enter}
return
}
if ch>8
{
IF InStr(A_ThisHotkey, "Numpad")
	last_sent_Numpad_command := A_ThisHotkey
send ^g
send %ch%
send {enter}
send {f9 3}
return
}
return

Re: Simple memory of lastpress

Posted: 18 Aug 2022, 01:05
by Rohwedder
it keeps adding +1 to ch?
Here with this code this does not happen:

Code: Select all

last_sent_Numpad_command  = Numpaddot
Numpad1::
ch=1
gosub sendroutine
return
Numpad2::
ch=9
gosub sendroutine
return
; ...
Numpad1 & Numpad2::
ch=122
gosub sendroutine
return
Numpad1 & Numpad3::
ch=137
gosub sendroutine
return
Numpaddot::
IF (last_sent_Numpad_command <> A_ThisHotkey)
	Goto, %last_sent_Numpad_command%
Return
sendroutine:
if ch between 0 and 8
{
	IF InStr(A_ThisHotkey, "Numpad")
		last_sent_Numpad_command := A_ThisHotkey
	send ^g
	send %ch%
	send {enter}
	return
}
if ch>8
{
	IF InStr(A_ThisHotkey, "Numpad")
		last_sent_Numpad_command := A_ThisHotkey
	send ^g
	send %ch%
	send {enter}
	send {f9 3}
	return
}
return
The Numpad+Number Hotkeys each send the ch value + Enter, Numpaddot:: repeats this.

Re: Simple memory of lastpress

Posted: 18 Aug 2022, 09:00
by blad4
Still the same issue. But what is the difference in the last code you sent? It seems letter for letter the same as what I had before?

Re: Simple memory of lastpress

Posted: 18 Aug 2022, 10:49
by Rohwedder
There should be no difference.
Read what I wrote about it. This "it keeps adding +1 to ch" does not happen here with that script!

Re: Simple memory of lastpress

Posted: 18 Aug 2022, 11:04
by Xtra
Something different:

Code: Select all

#NoEnv

Numpad1::sendroutine(last_sent_Numpad_command := "Numpad1")
Numpad2::sendroutine(last_sent_Numpad_command := "Numpad2")
Numpad1 & Numpad2::sendroutine(last_sent_Numpad_command := "Numpad1 & Numpad2")
Numpad1 & Numpad3::sendroutine(last_sent_Numpad_command := "Numpad1 & Numpad3")

NumpadDot::
    if (last_sent_Numpad_command)
	    Goto, %last_sent_Numpad_command%
return

sendroutine(A_Hotkey) {
    static ch := {"Numpad1":1,"Numpad2":9,"Numpad1 & Numpad2":122,"Numpad1 & Numpad3":137}
	send ^g
	send % n := ch[A_Hotkey]
	send {enter}
	if (n > 8)
        send {f9 3}
}

Re: Simple memory of lastpress

Posted: 18 Aug 2022, 18:39
by blad4
Rohwedder wrote:
18 Aug 2022, 01:05
it keeps adding +1 to ch?
Here with this code this does not happen:

Code: Select all

last_sent_Numpad_command  = Numpaddot
Numpad1::
ch=1
gosub sendroutine
return
Numpad2::
ch=9
gosub sendroutine
return
; ...
Numpad1 & Numpad2::
ch=122
gosub sendroutine
return
Numpad1 & Numpad3::
ch=137
gosub sendroutine
return
Numpaddot::
IF (last_sent_Numpad_command <> A_ThisHotkey)
	Goto, %last_sent_Numpad_command%
Return
sendroutine:
if ch between 0 and 8
{
	IF InStr(A_ThisHotkey, "Numpad")
		last_sent_Numpad_command := A_ThisHotkey
	send ^g
	send %ch%
	send {enter}
	return
}
if ch>8
{
	IF InStr(A_ThisHotkey, "Numpad")
		last_sent_Numpad_command := A_ThisHotkey
	send ^g
	send %ch%
	send {enter}
	send {f9 3}
	return
}
return
The Numpad+Number Hotkeys each send the ch value + Enter, Numpaddot:: repeats this.
With this exact code, and when ch<9, numpaddot increases ch by 1. When ch>9, it increases ch by 4

Re: Simple memory of lastpress

Posted: 18 Aug 2022, 18:40
by blad4
Xtra wrote:
18 Aug 2022, 11:04
Something different:

Code: Select all

#NoEnv

Numpad1::sendroutine(last_sent_Numpad_command := "Numpad1")
Numpad2::sendroutine(last_sent_Numpad_command := "Numpad2")
Numpad1 & Numpad2::sendroutine(last_sent_Numpad_command := "Numpad1 & Numpad2")
Numpad1 & Numpad3::sendroutine(last_sent_Numpad_command := "Numpad1 & Numpad3")

NumpadDot::
    if (last_sent_Numpad_command)
	    Goto, %last_sent_Numpad_command%
return

sendroutine(A_Hotkey) {
    static ch := {"Numpad1":1,"Numpad2":9,"Numpad1 & Numpad2":122,"Numpad1 & Numpad3":137}
	send ^g
	send % n := ch[A_Hotkey]
	send {enter}
	if (n > 8)
        send {f9 3}
}
Thanks, but because this does not affect ch again, gives me problems.

Example, pressed Numpad2... then NumpadDot, ch should now become 9 to replicate the original Numpad2 press again.

Re: Simple memory of lastpress

Posted: 19 Aug 2022, 01:53
by Xtra
Did you even try it? Press any hotkey and NumpadDot will repeat the last used hotkey.
Are you are using ch somewhere else in your script that you are not showing here?

If you wanted something else please explain what that is so anyone answering here can understand.

Re: Simple memory of lastpress

Posted: 19 Aug 2022, 06:15
by blad4
Yes of course I applied it to my script and tried it, and yes using ch for many different things in the script, that is why the functionality needs to affect ch.

Re: Simple memory of lastpress

Posted: 19 Aug 2022, 06:17
by blad4
Maybe a better way to explain:

Code: Select all

NumpadX::
ch=Y
gosub sendroutine
return

Somewhere we hold the memory of X

NumpadDot repress that NumPadX

Re: Simple memory of lastpress  Topic is solved

Posted: 19 Aug 2022, 12:22
by Xtra
The ch value can be returned from the function and saved to a var named ch. Then it can be used in parts of your script not shown here.

Simplified the script some:

Code: Select all

#NoEnv

Numpad1::
Numpad2::
Numpad1 & Numpad2::
Numpad1 & Numpad3::ch := sendroutine(last_sent_Numpad_command := A_ThisLabel)

NumpadDot::
    if (last_sent_Numpad_command)
	    Goto, %last_sent_Numpad_command%
return

sendroutine(A_Hotkey) {
    static chArr := {"Numpad1":1,"Numpad2":9,"Numpad1 & Numpad2":122,"Numpad1 & Numpad3":137}
	send ^g
	send % n := chArr[A_Hotkey]
	send {enter}
	if (n > 8)
        send {f9 3}
	return n
}

Re: Simple memory of lastpress

Posted: 19 Aug 2022, 18:27
by blad4
Works a charm. Thank you Xtra and thank you Rohwedder (and sorry to you also for my confusion).

Re: Simple memory of lastpress

Posted: 31 Aug 2022, 17:56
by blad4
May I ask how to do more than one thing from the numpad press, for example:

Code: Select all

sendcharts(A_Hotkey) {
    static chArr := {"Numpad1":1,"Numpad2":3,"Numpad3":15,"Numpad4":27,"Numpad5":39,"Numpad6":51,"Numpad7":63}
	send ^g
	send % n := chArr[A_Hotkey]
	send {enter}
	;;;;;;;;;;;; add one to n.. (n+1), then send % n again
	send ^g
	send % n := chArr[A_Hotkey]
	send {enter}

Re: Simple memory of lastpress

Posted: 31 Aug 2022, 22:03
by Xtra
send % n+1 ; add one to n.. (n+1), then send % n again