Geliche Kürzel über und IfWinActive Topic is solved

Stelle Fragen zur Programmierung mit Autohotkey

Moderator: jNizM

ingopepe
Posts: 2
Joined: 05 Jun 2019, 08:10

Geliche Kürzel über und IfWinActive

05 Jun 2019, 08:19

Hallo

Ich habe im generellen Teil mein Skript eine Ersetzung (#d) um das aktuelle Datum einzufügen.

Code: Select all

; Kurzdatum – #d
::#d::
  FormatTime,Datum,,dd.MM.yyyy
  sendinput, %Datum% 
return
Nun würde ich dieses Kürzel aber in einigen Anwendungen anders belegen. Also z.B. in One Note.
Also habe ich meine Skript diesen Teil hinzugefügt.

Code: Select all

#IfWinActive ahk_exe ONENOTE.EXE
; Kurzdatum – #d mit Doppelpunkt in One Note
  ::#d::
	FormatTime,Datum,,dd.MM.yyyy
	sendinput, %Datum%:{space} 
  return
#If ; Bedingung aufheben
Allerdings klappt das nicht. Wo ist mein Denkfehler?

Viele Grüße Ingo
gregster
Posts: 9012
Joined: 30 Sep 2013, 06:48

Re: Geliche Kürzel über und IfWinActive

05 Jun 2019, 10:31

Willkommen im Forum!

Funktioniert der Hotstring denn in OneNote, wenn du die #IfWin-Direktive weglässt?
Wenn nicht, probier's mal, das Skript als Administrator auszuführen... denn dann läuft OneNote wahrscheinlich mit höheren Rechten als dein Skript.
Kobaltauge
Posts: 264
Joined: 09 Mar 2019, 01:52
Location: Germany
Contact:

Re: Geliche Kürzel über und IfWinActive  Topic is solved

05 Jun 2019, 10:35

Das Problem ist die Reihenfolge. AHK reagiert auf das #d noch bevor die if Abfrage stattfindet. Wenn du es so machst, dann funktioniert es.

Code: Select all

#IfWinActive ahk_exe ONENOTE.EXE
; Kurzdatum – #d mit Doppelpunkt in One Note
  ::#d::
FormatTime,Datum,,dd.MM.yyyy
sendinput, %Datum%:{space} 
return
#If ; Bedingung aufheben

; Kurzdatum – #d
::#d::
FormatTime,Datum,,dd.MM.yyyy
sendinput, %Datum% 
return
gregster
Posts: 9012
Joined: 30 Sep 2013, 06:48

Re: Geliche Kürzel über und IfWinActive

05 Jun 2019, 10:44

Ja, guter Punkt, da es sich hier um Hotstrings handelt - bei Hotkeys wär's anders:
https://www.autohotkey.com/docs/commands/_IfWinActive.htm#variant wrote:If more than one variant is eligible to fire, only the one closest to the top of the script will fire. The exception to this is the global variant (the one with no #IfWin criteria): It always has the lowest precedence; therefore, it will fire only if no other variant is eligible (this exception does not apply to hotstrings).
ingopepe
Posts: 2
Joined: 05 Jun 2019, 08:10

Re: Geliche Kürzel über und IfWinActive

18 Jun 2019, 05:01

Super, das wars.
Ich habe die Reihenfolge geändert und jetzt geht es wie gewünscht.
Vielen Dank für die Hilfe.

Return to “Ich brauche Hilfe”

Who is online

Users browsing this forum: No registered users and 50 guests