Need Help With Advanced Hotstring Display Thing Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
The_One_True_Rick
Posts: 65
Joined: 25 May 2023, 17:14

Need Help With Advanced Hotstring Display Thing

Post by The_One_True_Rick » 31 May 2023, 19:57

Trying to make a pop up menu that displays drug names while you are typing them out. Ideally you'll be able to just hit space or something once you have it narrowed down to one drug. Right now its just on tooltip until I get basic functionality all worked out. Works for the most part so far. Just need help with getting it to reset with backspace, right now it only resets with space bar. Just a display so far, does not send the text but i'm thinking I can just figure out where I am at send the right amount of backspaces followed by whatever is on the tooltip variable at that point. Have it so it will update and narrow down the list as you type. Starts to pick up at 3 letters and will continue to narrow down the list to 6 letters. That seems to be enough to get it down to one drug so far. I cut out most of the drug list in this example because its crazy long and doesn't matter.

Code: Select all

Length := 3

Drug_List =
(
Buprenorphine/Naloxone (Suboxone)
Carisoprodol (Soma)
Celecoxib (Celebrex)
Amitriptyline (Elavil)
Mirtazapine (Remeron SolTab, Remeron)
Nortriptyline (Aventyl, Pamelor)
Trazodone (Desyrel)
Citalopram (Cipramil)
Dapoxetine (Priligy)
Escitalopram (Cipralex)
Fluoxetine (Prozac, Oxactin)
Fluvoxamine (Faverin)
Paroxetine (Seroxat)
Sertraline (Lustral)
Vortioxetine (Brintellix)
)

Generate_Hotstrings:
Loop, 4
	{
	Abbreviation_Length := 3+(A_Index-1)
	Loop, Parse, Drug_List, `n
		{
		NewStr := SubStr(A_LoopField, 1, Abbreviation_Length)
		Hotstring(":C1B0X*:" NewStr, "Drug_Menu")
		}
	}
return

Drug_Menu:
Tooltip_Text := ""

Loop, Parse, Drug_List, `n
	{
	NewStr2 := RegExReplace(A_ThisHotkey, "(:C1B0X\*:)", "")
	if (NewStr2 ~= "i)" SubStr(A_LoopField, 1, Length))
		{
		Tooltip_Text .= A_LoopField "`n"
		}
	}

ToolTip, %Tooltip_Text%
Length := Length + 1

KeyWait, Space, D

ToolTip,
Length := 3
Tooltip_Text := ""

return

[Mod edit: Added [code][/code] tags. Please use them yourself when posting code!] This has been noted in several of your posts. This is not meant to be a service provided by the forum staff. Add them yourself or your posts will just be disapproved going forward. Thank you.]

Rohwedder
Posts: 7551
Joined: 04 Jun 2014, 08:33
Location: Germany

Re: Need Help With Advanced Hotstring Display Thing

Post by Rohwedder » 01 Jun 2023, 10:10

Hallo,
perhaps?:

Code: Select all

Drug_List =
(
Buprenorphine/Naloxone (Suboxone)
Carisoprodol (Soma)
Celecoxib (Celebrex)
Amitriptyline (Elavil)
Mirtazapine (Remeron SolTab, Remeron)
Nortriptyline (Aventyl, Pamelor)
Trazodone (Desyrel)
Citalopram (Cipramil)
Dapoxetine (Priligy)
Escitalopram (Cipralex)
Fluoxetine (Prozac, Oxactin)
Fluvoxamine (Faverin)
Paroxetine (Seroxat)
Sertraline (Lustral)
Vortioxetine (Brintellix)
)
Sort, Drug_List, U
Drugs := StrSplit(Drug_List, "`n")
Generate_Hotstrings:
Loop
{
	Length := 3+(A_Index-1), OldStr := ""
	Repeat:
	For All, Drug in Drugs
	{
		IF ((NewStr:=SubStr(Drug, 1, Length))
			<> SubStr(Drugs[All+1], 1, Length))
		And (OldStr <> NewStr)
		{
			Hotstring(":C1*:" NewStr, Drug)
			Drugs.RemoveAt(All)
			IF Drugs.Length()
				Goto, Repeat
			Else Return
			}
		Else Hotstring(":C1B0X*:" NewStr, "Drug_Menu")
		OldStr := NewStr
	}
}
Drug_Menu:
Tooltip_Text := ""
Loop, Parse, Drug_List, `n
	If InStr(A_LoopField, StrReplace(A_ThisHotkey, ":C1B0X*:")) = 1
		Tooltip_Text .= A_LoopField "`n"
ToolTip, %Tooltip_Text%
SetTimer, ToolTip, -3000
Return
ToolTip:
ToolTip
Return

The_One_True_Rick
Posts: 65
Joined: 25 May 2023, 17:14

Re: Need Help With Advanced Hotstring Display Thing

Post by The_One_True_Rick » 01 Jun 2023, 11:47

Pretty cool. It helps for sure thanks. Still need to figure out how to make triggering the hotstring optional. I'm going to make it conditional which will help but even if I narrow it down to being conditional on the right window it won't be enough if it sends automatically. Maybe if I can make it conditional for a specific control since I only have one edit box to type prescription history in. I'll look into it but does anyone know if its possible to make it control conditional?

Rohwedder
Posts: 7551
Joined: 04 Jun 2014, 08:33
Location: Germany

Re: Need Help With Advanced Hotstring Display Thing

Post by Rohwedder » 01 Jun 2023, 12:22

Try:

Code: Select all

…
Generate_Hotstrings:
Hotkey, IfWinActive, ahk_class Notepad ;<<<<<<<<<
Loop
{
…

The_One_True_Rick
Posts: 65
Joined: 25 May 2023, 17:14

Re: Need Help With Advanced Hotstring Display Thing

Post by The_One_True_Rick » 01 Jun 2023, 13:07

This worked to make it control specific on my gui. Thanks a lot for all the help! Still ideally need a way to make it optional to trigger since it does not contain the names of all the drugs but this will work fine for now. Thanks again!

Code: Select all

Drug_List =
(
Buprenorphine/Naloxone (Suboxone)
Carisoprodol (Soma)
Celecoxib (Celebrex)
Pitavastatin (Livalo)
Pravastatin (Pravachol)
Rosuvastatin (Crestor)
Simvastatin (Zocor)
Niacin
Ezetimibe (Zetia)
Ezetimibe/Simvastatin (Vytorin)
Acetazolamide (Diamox)
Amiloride (Midamor)
Bumetanide (Bumex)
Chlorothiazide (Diuril)
Chlorthalidone (Hygroton)
Furosemide (Lasix)
Hydro-chlorothiazide (Esidrix, Hydrodiuril)
Indapamide (Lozol)
Metalozone (Zaroxolyn)
Spironolactone (Aldactone)
Torsemide (Demadex)
Isosorbide dinitrate (Isordil)
Isosorbide mononitrate (Imdur)
Hydralazine (Apresoline)
Nitroglycerin (Nitro Bid, Nitro Stat)
Minoxidil
Alprazolam (Xanax)
Chlordiazepoxide (Librium)
Clorazepate (Tranxene)
Diazepam (Valium)
Halazepam (Paxipam)
Lorzepam (Ativan)
Oxazepam (Serax)
Prazepam (Centrax)
Quazepam (Doral)
Clonazepam (Klonopin)
Zolpidem (Ambien, Edluar, Intermezzo)
Zaleplon (Sonata)
Suvorexant (Belsomra)
Ramelteon (Rozerem)
Eszopiclone (Lunesta)
Doxepine (Silenor)
Amitriptyline (Elavil)
Mirtazapine (Remeron SolTab, Remeron)
Nortriptyline (Aventyl, Pamelor)
Trazodone (Desyrel)
Citalopram (Cipramil)
Dapoxetine (Priligy)
Escitalopram (Cipralex)
Fluoxetine (Prozac, Oxactin)
Fluvoxamine (Faverin)
Paroxetine (Seroxat)
Sertraline (Lustral)
Vortioxetine (Brintellix)
Methylphenidate (Concerta, Quillivant XR, Ritalin)
Dexmethylphenidate (Focalin XR)
Atomoxetine (Strattera)
Dextroamphetamine (Dexedrine)
Amphetamine Sulfate (Evekeo)
Amphetamine/Dextroamphetamine (Adderall XR, Adderall IR)
)

Sort, Drug_List, U
Drugs := StrSplit(Drug_List, "`n")
Generate_Hotstrings:
#if (Active_Control("Consult_GUI") = "Edit7")
Hotkey, If, (Active_Control("Consult_GUI") = "Edit7")

Loop
{
	Length := 3+(A_Index-1), OldStr := ""
	Repeat:
	For All, Drug in Drugs
	{
		IF ((NewStr:=SubStr(Drug, 1, Length))
			<> SubStr(Drugs[All+1], 1, Length))
		And (OldStr <> NewStr)
		{
			Hotstring(":C1*:" NewStr, Drug)
			Drugs.RemoveAt(All)
			IF Drugs.Length()
				Goto, Repeat
			Else Return
			}
		Else Hotstring(":C1B0X*:" NewStr, "Drug_Menu")
			OldStr := NewStr
	}
}
Drug_Menu:
Tooltip_Text := ""
Loop, Parse, Drug_List, `n
	{
	If InStr(A_LoopField, StrReplace(A_ThisHotkey, ":C1B0X*:")) = 1
		Tooltip_Text .= A_LoopField "`n"
	}
ToolTip, %Tooltip_Text%
SetTimer, ToolTip, -5000
Hotkey, If,
#if
Return
ToolTip:
ToolTip
Return

Active_Control(Window_Title){
	ControlGetFocus, OutputVar, %Window_Title%
	return OutputVar
}
Last edited by joedf on 01 Jun 2023, 14:45, edited 1 time in total.
Reason: fix [code] tags

Rohwedder
Posts: 7551
Joined: 04 Jun 2014, 08:33
Location: Germany

Re: Need Help With Advanced Hotstring Display Thing

Post by Rohwedder » 02 Jun 2023, 02:45

Now with a clickable selection gui:

Code: Select all

Drug_List =
(
Buprenorphine/Naloxone (Suboxone)
Carisoprodol (Soma)
Celecoxib (Celebrex)
Pitavastatin (Livalo)
Pravastatin (Pravachol)
Rosuvastatin (Crestor)
Simvastatin (Zocor)
Niacin
Ezetimibe (Zetia)
Ezetimibe/Simvastatin (Vytorin)
Acetazolamide (Diamox)
Amiloride (Midamor)
Bumetanide (Bumex)
Chlorothiazide (Diuril)
Chlorthalidone (Hygroton)
Furosemide (Lasix)
Hydro-chlorothiazide (Esidrix, Hydrodiuril)
Indapamide (Lozol)
Metalozone (Zaroxolyn)
Spironolactone (Aldactone)
Torsemide (Demadex)
Isosorbide dinitrate (Isordil)
Isosorbide mononitrate (Imdur)
Hydralazine (Apresoline)
Nitroglycerin (Nitro Bid, Nitro Stat)
Minoxidil
Alprazolam (Xanax)
Chlordiazepoxide (Librium)
Clorazepate (Tranxene)
Diazepam (Valium)
Halazepam (Paxipam)
Lorzepam (Ativan)
Oxazepam (Serax)
Prazepam (Centrax)
Quazepam (Doral)
Clonazepam (Klonopin)
Zolpidem (Ambien, Edluar, Intermezzo)
Zaleplon (Sonata)
Suvorexant (Belsomra)
Ramelteon (Rozerem)
Eszopiclone (Lunesta)
Doxepine (Silenor)
Amitriptyline (Elavil)
Mirtazapine (Remeron SolTab, Remeron)
Nortriptyline (Aventyl, Pamelor)
Trazodone (Desyrel)
Citalopram (Cipramil)
Dapoxetine (Priligy)
Escitalopram (Cipralex)
Fluoxetine (Prozac, Oxactin)
Fluvoxamine (Faverin)
Paroxetine (Seroxat)
Sertraline (Lustral)
Vortioxetine (Brintellix)
Methylphenidate (Concerta, Quillivant XR, Ritalin)
Dexmethylphenidate (Focalin XR)
Atomoxetine (Strattera)
Dextroamphetamine (Dexedrine)
Amphetamine Sulfate (Evekeo)
Amphetamine/Dextroamphetamine (Adderall XR, Adderall IR)
)
Sort, Drug_List, U
Drugs := StrSplit(Drug_List, "`n")
Generate_Hotstrings:
Hotkey, IfWinActive, ahk_class Notepad ;<<<<<<<<<<<<<<<<
Loop
{
    Length := 3+(A_Index-1), OldStr := ""
    Repeat:
    For All, Drug in Drugs
    {
        IF ((NewStr:=SubStr(Drug, 1, Length))
            <> SubStr(Drugs[All+1], 1, Length))
			And (OldStr <> NewStr)
        {
            Hotstring(":C1*:" NewStr, Drug)
            Drugs.RemoveAt(All)
            IF Drugs.Length()
                Goto, Repeat
            Else Break, 2
        }
        Else Hotstring(":C1B0X*:" NewStr, "Drug_Menu")
        OldStr := NewStr
    }
}
Drugs := StrSplit(Drug_List, "`n")
Return
Drug_Menu:
Length := StrLen(Shortcut := SubStr(A_ThisHotkey, 9))
Gui, Drugs: Destroy
Gui, Drugs:-Caption +Toolwindow +AlwaysOnTop
Gui, Drugs:Margin, 0, 0
For All, Drug in Drugs
    If (Shortcut = SubStr(Drug, 1, Length))
        Gui, Drugs:Add, Edit,vE%A_Index%,% Drug
CoordMode, Mouse, Screen
MouseGetPos, Gx, Gy
Gui, Drugs:Show, x%Gx% y%Gy% NA
OnMessage(0x0201, "WM_LBUTTONDOWN")
SetTimer, RemoveGui, -3000
Return
RemoveGui:
Gui, Drugs: Destroy
Return
WM_LBUTTONDOWN()
{
	Global
	Drug := "{Bs " StrLen(Shortcut) "}" Drugs[SubStr(A_GuiControl,2)]
	Gui, Drugs: Destroy
	SendInput,% Drug
}

The_One_True_Rick
Posts: 65
Joined: 25 May 2023, 17:14

Re: Need Help With Advanced Hotstring Display Thing

Post by The_One_True_Rick » 02 Jun 2023, 16:02

Oh nice that's really cool. Thanks!

The_One_True_Rick
Posts: 65
Joined: 25 May 2023, 17:14

Re: Need Help With Advanced Hotstring Display Thing

Post by The_One_True_Rick » 03 Jun 2023, 08:12

That helped a lot its almost perfect now. I removed the * from the if = hotstring so it only sends if you hit space. Now I'm just trying to get the gui to update with that hotstring too so you know what you are about to send if you hit space and that will be perfect! Thanks for all the help everyone!

The_One_True_Rick
Posts: 65
Joined: 25 May 2023, 17:14

Re: Need Help With Advanced Hotstring Display Thing

Post by The_One_True_Rick » 04 Jun 2023, 08:23

Still needs some work but moving toward something like this. Love the clickable GUI thing, thanks for that. Got rid of the timer because it would disappear when I didn't want it too. This feels more natural using input hook. Doesn't completely work yet but its very close. If anyone has any idea how to manage having the GUI destroy on space but also not do that when the drug name has a space in it that would be appreciated. Also trying to use an array to keep all the hotkey abbreviations in to compare that to the current string you are typing so that the GUI will also destroy if you misspell something or as soon as it realizes you are typing something that is not on the list. This seems like the way to go though. Input hook offers way more options. Have a few extra lines in there now because i'm not as good with the fancy syntax you had in there before and I couldn't get that to work. Thanks everyone!

Code: Select all

Medication_InputHook := InputHook("V", "{Space}{Enter}")
Medication_InputHook.OnEnd := Func("InputHook_End")
Medication_InputHook.OnChar := Func("InputHook_Char")
Medication_InputHook.Start()

Drug_List =
(
Buprenorphine/Naloxone (Suboxone)
Carisoprodol (Soma)
Celecoxib (Celebrex)
Codeine
Cyclobenzaprine (Flexeril)
Diclofenac (Voltaren)
Fentanyl
Hydrocodone
Hydrocodone/APAP (Vicodin)
Ibuprofen (Advil)
Indomethacin
Lidocaine
Meloxicam (Mobic)
Methadone
Methocarbamol (Robaxin)
Morphine (MS Contin)
Naproxen (Aleve)
Oxycodone (OxyContin)
Pentosan (Elmiron)
Sumatriptan (Imitrex)
Tramadol (Ultram)
Benazepril (Lotensin)
Captopril (Capoten)
Enalapril (Vasotec)
Fosinopril (Monopril)
Lisinopril (Prinivil, Zestril)
Moexipril (Univasc)
Perindopril (Aceon)
Quinapril (Accupril)
Ramipril (Altace)
Trandolapril (Mavik)
Azilsartan (Edarbi)
Candesartan (Atacand)
Eprosartan (Teveten)
Irbesartan (Avapro)
Losartan (Cozaar)
Olmesartan (Benicar)
Telmisartan (Micardis)
Valsartan (Diovan)
Apixaban (Eliquis)
Dabigatran (Pradaxa)
Edoxaban (Savaysa)
Heparin
Rivaroxaban (Xarelto)
Warfarin (Coumadin)
Aspirin
Clopidogrel (Plavix)
Dipyridamole (Persantine)
Prasugrel (Effient)
Ticagrelor (Brilinta)
Acebutolol (Sectral)
Atenolol (Tenormin)
Betaxolol (Kerlone)
Bisoprolol/hydrochlorothiazide (Ziac)
Bisoprolol (Zebeta)
Metoprolol (Lopressor, Toprol XL)
Nadolol (Corgard)
Propranolol (Inderal)
Sotalol (Betapace)
Carvedilol (Coreg, Coreg CR)
Labetalol hydrochloride (Normodyne, Trandate)
Amlodipine (Norvasc)
Diltiazem (Cardizem, Tiazac)
Felodipine (Plendil)
Nifedipine (Adalat, Procardia)
Nimodipine (Nimotop)
Nisoldipine (Sular)
Verapamil (Calan, Verelan)
Digoxin (Lanoxin)
Atorvastatin (Lipitor)
Fluvastatin (Lescol)
Lovastatin (Mevacor)
Pitavastatin (Livalo)
Pravastatin (Pravachol)
Rosuvastatin (Crestor)
Simvastatin (Zocor)
Niacin
Ezetimibe (Zetia)
Ezetimibe/Simvastatin (Vytorin)
Acetazolamide (Diamox)
Amiloride (Midamor)
Bumetanide (Bumex)
Chlorothiazide (Diuril)
Chlorthalidone (Hygroton)
Furosemide (Lasix)
Hydro-chlorothiazide (Esidrix, Hydrodiuril)
Indapamide (Lozol)
Metalozone (Zaroxolyn)
Spironolactone (Aldactone)
Torsemide (Demadex)
Isosorbide dinitrate (Isordil)
Isosorbide mononitrate (Imdur)
Hydralazine (Apresoline)
Nitroglycerin (Nitro Bid, Nitro Stat)
Minoxidil
Alprazolam (Xanax)
Chlordiazepoxide (Librium)
Clorazepate (Tranxene)
Diazepam (Valium)
Halazepam (Paxipam)
Lorzepam (Ativan)
Oxazepam (Serax)
Prazepam (Centrax)
Quazepam (Doral)
Clonazepam (Klonopin)
Zolpidem (Ambien, Edluar, Intermezzo)
Zaleplon (Sonata)
Suvorexant (Belsomra)
Ramelteon (Rozerem)
Eszopiclone (Lunesta)
Doxepine (Silenor)
Amitriptyline (Elavil)
Mirtazapine (Remeron SolTab, Remeron)
Nortriptyline (Aventyl, Pamelor)
Trazodone (Desyrel)
Citalopram (Cipramil)
Dapoxetine (Priligy)
Escitalopram (Cipralex)
Fluoxetine (Prozac, Oxactin)
Fluvoxamine (Faverin)
Paroxetine (Seroxat)
Sertraline (Lustral)
Vortioxetine (Brintellix)
Methylphenidate (Concerta, Quillivant XR, Ritalin)
Dexmethylphenidate (Focalin XR)
Atomoxetine (Strattera)
Dextroamphetamine (Dexedrine)
Amphetamine Sulfate (Evekeo)
Amphetamine/Dextroamphetamine (Adderall XR, Adderall IR)
)

Sort, Drug_List, U
Drugs := StrSplit(Drug_List, "`n")

Generate_Hotstrings:

#if (Active_Control("Consult_GUI") = "Edit7")
Hotkey, If, (Active_Control("Consult_GUI") = "Edit7")

List_Of_Active_Hotstrings := []

Loop, 4
	{
	Abbreviation_Length := 3+(A_Index-1)
	For All, Drug in Drugs
		{
		NewStr := SubStr(Drug, 1, Abbreviation_Length)
		Hotstring(":C1B0X*:" NewStr, "Drug_Menu")
		List_Of_Active_Hotstrings.Push(NewStr)
		}
	}

return

Drug_Menu:
Length := StrLen(Shortcut := SubStr(A_ThisHotkey, 9))
Gui, Drugs: Destroy
Gui, Drugs:-Caption +Toolwindow +AlwaysOnTop
Gui, Drugs:Margin, 0, 0

Loop, Parse, Drug_List, `n
	{
	NewStr2 := RegExReplace(A_ThisHotkey, "(:C1B0X\*:)", "")
	if (NewStr2 ~= "i)" SubStr(A_LoopField, 1, Length))
		{
		Gui, Drugs:Add, Edit,vE%A_Index%, %A_LoopField%
		global Text := A_LoopField
		}
	}

CoordMode, Mouse, Screen
MouseGetPos, Gx, Gy
Gui, Drugs:Show, x%Gx% y%Gy% NA, Drugs
OnMessage(0x0201, "WM_LBUTTONDOWN")
return

RemoveGui:
Gui, Drugs: Destroy
Return

InputHook_End(ih){
	Reason := ih.EndReason
	KeyName := ih.EndKey
	Current_String := ih.Input
	num := StrLen(Current_String) + 1
	if (KeyName = "Enter") && if WinExist("Drugs")
		{
		SendInput, {Backspace %num%}
		SendInput, %Text%
		Gui, Drugs: Destroy
		}
	else if (KeyName = "Space")
		Gui, Drugs: Destroy
	ih.Start()
}

InputHook_Char(ih, char){
	;Current_String := ih.Input
	;ToolTip, %String%
}

WM_LBUTTONDOWN(){
	Global
	Drug := "{Bs " StrLen(Shortcut) "}" Drugs[SubStr(A_GuiControl,2)]
	Gui, Drugs: Destroy
	SendInput,% Drug
}

Active_Control(Window_Title){
	ControlGetFocus, OutputVar, %Window_Title%
	return OutputVar
}

Hotkey, If,
#if

[Mod edit: Added [code][/code] tags. Failure to do so yourself will result in your posts being deleted!]

The_One_True_Rick
Posts: 65
Joined: 25 May 2023, 17:14

Re: Need Help With Advanced Hotstring Display Thing

Post by The_One_True_Rick » 04 Jun 2023, 08:35

Also if anyone has any ideas on how to make it trigger for all the brand names without having to manually put those all on the drug list I'm working on that too. I'm thinking one of those regex match loops to match all the brand names in parenthesis after the generic name. I'd like the brand names to trigger like Brand (Generic). So if in the loop it matches each item separated by a comma and then puts the word not in parentheses on the current list (Generic) in parenthesis after it. Hard to describe it but I have the idea in my head just haven't been able to get it working yet. That would save me a lot of time by just keeping the generic (brand list) syntax I have now instead of adding a new line for each brand since I will be adding new drugs to the list all the time because new drugs are always coming out on the market. Its needed because sometimes you want to just type the brand and I still want that to pop up without having to think of the generic name first and then type that.

Rohwedder
Posts: 7551
Joined: 04 Jun 2014, 08:33
Location: Germany

Re: Need Help With Advanced Hotstring Display Thing

Post by Rohwedder » 04 Jun 2023, 12:45

(Without the latest requirements), try:

Code: Select all

Drug_List =
(
Buprenorphine/Naloxone (Suboxone)
Carisoprodol (Soma)
Celecoxib (Celebrex)
Codeine
Cyclobenzaprine (Flexeril)
Diclofenac (Voltaren)
Fentanyl
Hydrocodone
Hydrocodone/APAP (Vicodin)
Ibuprofen (Advil)
Indomethacin
Lidocaine
Meloxicam (Mobic)
Methadone
Methocarbamol (Robaxin)
Morphine (MS Contin)
Naproxen (Aleve)
Oxycodone (OxyContin)
Pentosan (Elmiron)
Sumatriptan (Imitrex)
Tramadol (Ultram)
Benazepril (Lotensin)
Captopril (Capoten)
Enalapril (Vasotec)
Fosinopril (Monopril)
Lisinopril (Prinivil, Zestril)
Moexipril (Univasc)
Perindopril (Aceon)
Quinapril (Accupril)
Ramipril (Altace)
Trandolapril (Mavik)
Azilsartan (Edarbi)
Candesartan (Atacand)
Eprosartan (Teveten)
Irbesartan (Avapro)
Losartan (Cozaar)
Olmesartan (Benicar)
Telmisartan (Micardis)
Valsartan (Diovan)
Apixaban (Eliquis)
Dabigatran (Pradaxa)
Edoxaban (Savaysa)
Heparin
Rivaroxaban (Xarelto)
Warfarin (Coumadin)
Aspirin
Clopidogrel (Plavix)
Dipyridamole (Persantine)
Prasugrel (Effient)
Ticagrelor (Brilinta)
Acebutolol (Sectral)
Atenolol (Tenormin)
Betaxolol (Kerlone)
Bisoprolol/hydrochlorothiazide (Ziac)
Bisoprolol (Zebeta)
Metoprolol (Lopressor, Toprol XL)
Nadolol (Corgard)
Propranolol (Inderal)
Sotalol (Betapace)
Carvedilol (Coreg, Coreg CR)
Labetalol hydrochloride (Normodyne, Trandate)
Amlodipine (Norvasc)
Diltiazem (Cardizem, Tiazac)
Felodipine (Plendil)
Nifedipine (Adalat, Procardia)
Nimodipine (Nimotop)
Nisoldipine (Sular)
Verapamil (Calan, Verelan)
Digoxin (Lanoxin)
Atorvastatin (Lipitor)
Fluvastatin (Lescol)
Lovastatin (Mevacor)
Pitavastatin (Livalo)
Pravastatin (Pravachol)
Rosuvastatin (Crestor)
Simvastatin (Zocor)
Niacin
Ezetimibe (Zetia)
Ezetimibe/Simvastatin (Vytorin)
Acetazolamide (Diamox)
Amiloride (Midamor)
Bumetanide (Bumex)
Chlorothiazide (Diuril)
Chlorthalidone (Hygroton)
Furosemide (Lasix)
Hydro-chlorothiazide (Esidrix, Hydrodiuril)
Indapamide (Lozol)
Metalozone (Zaroxolyn)
Spironolactone (Aldactone)
Torsemide (Demadex)
Isosorbide dinitrate (Isordil)
Isosorbide mononitrate (Imdur)
Hydralazine (Apresoline)
Nitroglycerin (Nitro Bid, Nitro Stat)
Minoxidil
Alprazolam (Xanax)
Chlordiazepoxide (Librium)
Clorazepate (Tranxene)
Diazepam (Valium)
Halazepam (Paxipam)
Lorzepam (Ativan)
Oxazepam (Serax)
Prazepam (Centrax)
Quazepam (Doral)
Clonazepam (Klonopin)
Zolpidem (Ambien, Edluar, Intermezzo)
Zaleplon (Sonata)
Suvorexant (Belsomra)
Ramelteon (Rozerem)
Eszopiclone (Lunesta)
Doxepine (Silenor)
Amitriptyline (Elavil)
Mirtazapine (Remeron SolTab, Remeron)
Nortriptyline (Aventyl, Pamelor)
Trazodone (Desyrel)
Citalopram (Cipramil)
Dapoxetine (Priligy)
Escitalopram (Cipralex)
Fluoxetine (Prozac, Oxactin)
Fluvoxamine (Faverin)
Paroxetine (Seroxat)
Sertraline (Lustral)
Vortioxetine (Brintellix)
Methylphenidate (Concerta, Quillivant XR, Ritalin)
Dexmethylphenidate (Focalin XR)
Atomoxetine (Strattera)
Dextroamphetamine (Dexedrine)
Amphetamine Sulfate (Evekeo)
Amphetamine/Dextroamphetamine (Adderall XR, Adderall IR)
)
Sort, Drug_List, U
Drugs := StrSplit(Drug_List, "`n")
Generate_Hotstrings:
Hotkey, IfWinActive, ahk_class Notepad ;<<<<<<<<<<<<<<<<
Loop
{
    Length := 3+(A_Index-1), Break := True
    For All, Drug in Drugs
    {
        IF (StrLen(Drug) > Length)
		{
			Hotstring(":C1B0X*:" SubStr(Drug, 1, Length), "Drug_Menu")
			Break := False
		}
		Else IF (StrLen(Drug) = Length)
			Hotstring(":C1B0X*:" Drug, "GuiDestroy")
    }
	Until, Break	
}
Drugs := StrSplit(Drug_List, "`n")
Return
Drug_Menu:
Length := StrLen(Shortcut := SubStr(A_ThisHotkey, 9))
Gui, Drugs: Destroy
Gui, Drugs:-Caption +Toolwindow +AlwaysOnTop
Gui, Drugs:Margin, 0, 0
For All, Drug in Drugs
    If (Shortcut = SubStr(Drug, 1, Length))
        Gui, Drugs:Add, Edit,vE%A_Index%,% SendDrug := Drug
CoordMode, Mouse, Screen
MouseGetPos, Gx, Gy
Gui, Drugs:Show, x%Gx% y%Gy% NA
Hotkey, Enter, SendDrug, On
OnMessage(0x0201, "WM_LBUTTONDOWN")
Input, Key, VL1
Shortcut .= Key, Length++, Wrong := True
For All, Drug in Drugs
    If (Shortcut = SubStr(Drug, 1, Length))
		Wrong := False
IF Wrong
	Goto, GuiDestroy
Return
SendDrug:
SendInput,% "{Bs " StrLen(Shortcut) "}" SendDrug
GuiDestroy:
Hotkey, Enter, SendDrug, Off
Gui, Drugs: Destroy
Return
WM_LBUTTONDOWN()
{
	Global
	Drug := "{Bs " StrLen(Shortcut) "}" Drugs[SubStr(A_GuiControl,2)]
	Gui, Drugs: Destroy
	SendInput,% Drug
	SetTimer, GuiDestroy, -100
}

The_One_True_Rick
Posts: 65
Joined: 25 May 2023, 17:14

Re: Need Help With Advanced Hotstring Display Thing

Post by The_One_True_Rick » 04 Jun 2023, 12:56

Spellcheck thing works now so if you misspell a word that would be a hotstring the list goes away. Also moved the list so it shows relative to the cursor instead of the mouse.

Code: Select all

Medication_InputHook := InputHook("V", "{Space}{Enter}")
Medication_InputHook.OnEnd := Func("InputHook_End")
Medication_InputHook.OnChar := Func("InputHook_Char")
Medication_InputHook.NotifyNonText := true
Medication_InputHook.KeyOpt("{Backspace}", "N")
Medication_InputHook.OnKeyDown := Func("Backspace_Func")
Medication_InputHook.Start()

Drug_List =
(
Buprenorphine/Naloxone (Suboxone)
Carisoprodol (Soma)
Celecoxib (Celebrex)
Codeine
Cyclobenzaprine (Flexeril)
Diclofenac (Voltaren)
Fentanyl
Hydrocodone
Hydrocodone/APAP (Vicodin)
Ibuprofen (Advil)
Indomethacin
Lidocaine
Meloxicam (Mobic)
Methadone
Methocarbamol (Robaxin)
Morphine (MS Contin)
Naproxen (Aleve)
Oxycodone (OxyContin)
Pentosan (Elmiron)
Sumatriptan (Imitrex)
Tramadol (Ultram)
Benazepril (Lotensin)
Captopril (Capoten)
Enalapril (Vasotec)
Fosinopril (Monopril)
Lisinopril (Prinivil, Zestril)
Moexipril (Univasc)
Perindopril (Aceon)
Quinapril (Accupril)
Ramipril (Altace)
Trandolapril (Mavik)
Azilsartan (Edarbi)
Candesartan (Atacand)
Eprosartan (Teveten)
Irbesartan (Avapro)
Losartan (Cozaar)
Olmesartan (Benicar)
Telmisartan (Micardis)
Valsartan (Diovan)
Apixaban (Eliquis)
Dabigatran (Pradaxa)
Edoxaban (Savaysa)
Heparin
Rivaroxaban (Xarelto)
Warfarin (Coumadin)
Aspirin
Clopidogrel (Plavix)
Dipyridamole (Persantine)
Prasugrel (Effient)
Ticagrelor (Brilinta)
Acebutolol (Sectral)
Atenolol (Tenormin)
Betaxolol (Kerlone)
Bisoprolol/hydrochlorothiazide (Ziac)
Bisoprolol (Zebeta)
Metoprolol (Lopressor, Toprol XL)
Nadolol (Corgard)
Propranolol (Inderal)
Sotalol (Betapace)
Carvedilol (Coreg, Coreg CR)
Labetalol hydrochloride (Normodyne, Trandate)
Amlodipine (Norvasc)
Diltiazem (Cardizem, Tiazac)
Felodipine (Plendil)
Nifedipine (Adalat, Procardia)
Nimodipine (Nimotop)
Nisoldipine (Sular)
Verapamil (Calan, Verelan)
Digoxin (Lanoxin)
Atorvastatin (Lipitor)
Fluvastatin (Lescol)
Lovastatin (Mevacor)
Pitavastatin (Livalo)
Pravastatin (Pravachol)
Rosuvastatin (Crestor)
Simvastatin (Zocor)
Niacin
Ezetimibe (Zetia)
Ezetimibe/Simvastatin (Vytorin)
Acetazolamide (Diamox)
Amiloride (Midamor)
Bumetanide (Bumex)
Chlorothiazide (Diuril)
Chlorthalidone (Hygroton)
Furosemide (Lasix)
Hydro-chlorothiazide (Esidrix, Hydrodiuril)
Indapamide (Lozol)
Metalozone (Zaroxolyn)
Spironolactone (Aldactone)
Torsemide (Demadex)
Isosorbide dinitrate (Isordil)
Isosorbide mononitrate (Imdur)
Hydralazine (Apresoline)
Nitroglycerin (Nitro Bid, Nitro Stat)
Minoxidil
Alprazolam (Xanax)
Chlordiazepoxide (Librium)
Clorazepate (Tranxene)
Diazepam (Valium)
Halazepam (Paxipam)
Lorzepam (Ativan)
Oxazepam (Serax)
Prazepam (Centrax)
Quazepam (Doral)
Clonazepam (Klonopin)
Zolpidem (Ambien, Edluar, Intermezzo)
Zaleplon (Sonata)
Suvorexant (Belsomra)
Ramelteon (Rozerem)
Eszopiclone (Lunesta)
Doxepine (Silenor)
Amitriptyline (Elavil)
Mirtazapine (Remeron SolTab, Remeron)
Nortriptyline (Aventyl, Pamelor)
Trazodone (Desyrel)
Citalopram (Cipramil)
Dapoxetine (Priligy)
Escitalopram (Cipralex)
Fluoxetine (Prozac, Oxactin)
Fluvoxamine (Faverin)
Paroxetine (Seroxat)
Sertraline (Lustral)
Vortioxetine (Brintellix)
Methylphenidate (Concerta, Quillivant XR, Ritalin)
Dexmethylphenidate (Focalin XR)
Atomoxetine (Strattera)
Dextroamphetamine (Dexedrine)
Amphetamine Sulfate (Evekeo)
Amphetamine/Dextroamphetamine (Adderall XR, Adderall IR)
)

Sort, Drug_List, U
Drugs := StrSplit(Drug_List, "`n")

Generate_Hotstrings:

#if (Active_Control("Consult_GUI") = "Edit7")
Hotkey, If, (Active_Control("Consult_GUI") = "Edit7")

List_Of_Active_Hotstrings := []
List := ""
Loop, % List_Of_Active_Hotstrings.MaxIndex()
	List.= List_Of_Active_Hotstrings[A_Index] "`n"



Loop, 4
	{
	Abbreviation_Length := 3+(A_Index-1)
	For All, Drug in Drugs
		{
		NewStr := SubStr(Drug, 1, Abbreviation_Length)
		Hotstring(":C1B0X*:" NewStr, "Drug_Menu")
		List_Of_Active_Hotstrings.Push(NewStr)
		}
	}

return

Drug_Menu:
Length := StrLen(Shortcut := SubStr(A_ThisHotkey, 9))
Gui, Drugs: Destroy
Gui, Drugs:-Caption +Toolwindow +AlwaysOnTop
Gui, Drugs:Margin, 0, 0
Gui, Drugs:Color, 0x254C5A, 0x254C5A
Gui, Drugs:font, s13 bold

Loop, Parse, Drug_List, `n
	{
	NewStr2 := RegExReplace(A_ThisHotkey, "(:C1B0X\*:)", "")
	if (NewStr2 ~= "i)" SubStr(A_LoopField, 1, Length))
		{
		global GUI_Text := ""
		Gui, Drugs:Add, Edit, cWhite vE%A_Index%, %A_LoopField%
		GUI_Text := A_LoopField
		}
	}

CoordMode, Caret , Screen
Caret_Y := A_CaretY + 30
Gui, Drugs:Show, x%A_CaretX% y%Caret_Y% NA, Drugs
OnMessage(0x0201, "WM_LBUTTONDOWN")
return

InputHook_End(ih){
	Reason := ih.EndReason
	KeyName := ih.EndKey
	Current_String := ih.Input
	Backspace_Number := StrLen(Current_String) + 1
	if (KeyName = "Enter") && if WinExist("Drugs")
		{
		SendInput, {Backspace %Backspace_Number%}
		SendInput, %GUI_Text%
		Gui, Drugs: Destroy
		}
	else if (KeyName = "Space")
		Gui, Drugs: Destroy
	ih.Start()
}

InputHook_Char(ih, char){
	;Current_String := ih.Input
	;ToolTip, %String%
	if String not in List
		Gui, Drugs: Destroy
}

Backspace_Func(){
	Gui, Drugs: Destroy
}

WM_LBUTTONDOWN(){
	Global
	Drug := "{Bs " StrLen(Shortcut) "}" Drugs[SubStr(A_GuiControl,2)]
	Gui, Drugs: Destroy
	SendInput,% Drug
}

Active_Control(Window_Title){
	ControlGetFocus, OutputVar, %Window_Title%
	return OutputVar
}

Hotkey, If,
#if

[Mod edit: Added [code][/code] tags. Failure to do so yourself will result in your posts being deleted!]

User avatar
boiler
Posts: 16771
Joined: 21 Dec 2014, 02:44

Re: Need Help With Advanced Hotstring Display Thing

Post by boiler » 04 Jun 2023, 13:01

@The_One_True_RickPlease start using [code][/code] tags around your posted code, or we’ll just start deleting your posts rather than adding the code tags ourselves. You have ignored all moderator comments added to your posts, including the one added to your first post of this thread, which should have made this pretty clear. Do you need direction on how to add the tags?

Please acknowledge that you have read and understood this message.

The_One_True_Rick
Posts: 65
Joined: 25 May 2023, 17:14

Re: Need Help With Advanced Hotstring Display Thing

Post by The_One_True_Rick » 04 Jun 2023, 15:10

Ok sorry. Did not know what those were. I will do it from now on.

The_One_True_Rick
Posts: 65
Joined: 25 May 2023, 17:14

Re: Need Help With Advanced Hotstring Display Thing

Post by The_One_True_Rick » 04 Jun 2023, 15:23

Posting a code update. Hopefully this is the right way to use Code\Code now. My apologies.

Works with both brand and generics now. Gets stuck sometimes and won't work but otherwise its real close.

Code: Select all

Medication_InputHook := InputHook("V", "{Space}{Enter}")
Medication_InputHook.OnEnd := Func("InputHook_End")
Medication_InputHook.OnChar := Func("InputHook_Char")
Medication_InputHook.NotifyNonText := true
Medication_InputHook.KeyOpt("{Backspace}", "N")
Medication_InputHook.OnKeyDown := Func("Backspace_Func")
Medication_InputHook.Start()

Drug_List =
(
Buprenorphine/Naloxone (Suboxone)
Carisoprodol (Soma)
Celecoxib (Celebrex)
Codeine
Cyclobenzaprine (Flexeril)
Diclofenac (Voltaren)
Fentanyl
Hydrocodone
Hydrocodone/APAP (Vicodin)
Ibuprofen (Advil)
Indomethacin
Lidocaine
Meloxicam (Mobic)
Methadone
Methocarbamol (Robaxin)
Morphine (MS Contin)
Naproxen (Aleve)
Oxycodone (OxyContin)
Pentosan (Elmiron)
Sumatriptan (Imitrex)
Tramadol (Ultram)
Benazepril (Lotensin)
Captopril (Capoten)
Enalapril (Vasotec)
Fosinopril (Monopril)
Lisinopril (Prinivil, Zestril)
Moexipril (Univasc)
Perindopril (Aceon)
Quinapril (Accupril)
Ramipril (Altace)
Trandolapril (Mavik)
Azilsartan (Edarbi)
Candesartan (Atacand)
Eprosartan (Teveten)
Irbesartan (Avapro)
Losartan (Cozaar)
Olmesartan (Benicar)
Telmisartan (Micardis)
Valsartan (Diovan)
Apixaban (Eliquis)
Dabigatran (Pradaxa)
Edoxaban (Savaysa)
Heparin
Rivaroxaban (Xarelto)
Warfarin (Coumadin)
Aspirin
Clopidogrel (Plavix)
Dipyridamole (Persantine)
Prasugrel (Effient)
Ticagrelor (Brilinta)
Acebutolol (Sectral)
Atenolol (Tenormin)
Betaxolol (Kerlone)
Bisoprolol/hydrochlorothiazide (Ziac)
Bisoprolol (Zebeta)
Metoprolol (Lopressor, Toprol XL)
Nadolol (Corgard)
Propranolol (Inderal)
Sotalol (Betapace)
Carvedilol (Coreg, Coreg CR)
Labetalol hydrochloride (Normodyne, Trandate)
Amlodipine (Norvasc)
Diltiazem (Cardizem, Tiazac)
Felodipine (Plendil)
Nifedipine (Adalat, Procardia)
Nimodipine (Nimotop)
Nisoldipine (Sular)
Verapamil (Calan, Verelan)
Digoxin (Lanoxin)
Atorvastatin (Lipitor)
Fluvastatin (Lescol)
Lovastatin (Mevacor)
Pitavastatin (Livalo)
Pravastatin (Pravachol)
Rosuvastatin (Crestor)
Simvastatin (Zocor)
Niacin
Ezetimibe (Zetia)
Ezetimibe/Simvastatin (Vytorin)
Acetazolamide (Diamox)
Amiloride (Midamor)
Bumetanide (Bumex)
Chlorothiazide (Diuril)
Chlorthalidone (Hygroton)
Furosemide (Lasix)
Hydro-chlorothiazide (Esidrix, Hydrodiuril)
Indapamide (Lozol)
Metalozone (Zaroxolyn)
Spironolactone (Aldactone)
Torsemide (Demadex)
Isosorbide dinitrate (Isordil)
Isosorbide mononitrate (Imdur)
Hydralazine (Apresoline)
Nitroglycerin (Nitro Bid, Nitro Stat)
Minoxidil
Alprazolam (Xanax)
Chlordiazepoxide (Librium)
Clorazepate (Tranxene)
Diazepam (Valium)
Halazepam (Paxipam)
Lorzepam (Ativan)
Oxazepam (Serax)
Prazepam (Centrax)
Quazepam (Doral)
Clonazepam (Klonopin)
Zolpidem (Ambien, Edluar, Intermezzo)
Zaleplon (Sonata)
Suvorexant (Belsomra)
Ramelteon (Rozerem)
Eszopiclone (Lunesta)
Doxepine (Silenor)
Amitriptyline (Elavil)
Mirtazapine (Remeron SolTab, Remeron)
Nortriptyline (Aventyl, Pamelor)
Trazodone (Desyrel)
Citalopram (Cipramil)
Dapoxetine (Priligy)
Escitalopram (Cipralex)
Fluoxetine (Prozac, Oxactin)
Fluvoxamine (Faverin)
Paroxetine (Seroxat)
Sertraline (Lustral)
Vortioxetine (Brintellix)
Methylphenidate (Concerta, Quillivant XR, Ritalin)
Dexmethylphenidate (Focalin XR)
Atomoxetine (Strattera)
Dextroamphetamine (Dexedrine)
Amphetamine Sulfate (Evekeo)
Amphetamine/Dextroamphetamine (Adderall XR, Adderall IR)
)


Loop, Parse, Drug_List, `n
	{
	RegExMatch(A_LoopField, "iO)(?:\()(.*)(?:\))", Brand_List_Pat)
	Current_Drug_Brand_List := Brand_List_Pat.Value(1)
	if (Current_Drug_Brand_List != "")
		{
		Brand_Array := StrSplit(Current_Drug_Brand_List , ", ")
		for each, Brand in Brand_Array
			{
			Drug_Brand_Tag := RegExReplace(A_LoopField, "(\w*(?:\s\w*)?)\s\((.*)\)", Brand " ($1)")
			Drug_List.= "`n" Drug_Brand_Tag
			}
		}

	if (A_LoopField = "Amphetamine/Dextroamphetamine (Adderall XR, Adderall IR)")
		break
	}

Sort, Drug_List, U
Drugs := StrSplit(Drug_List, "`n")

Generate_Hotstrings:

#if (Active_Control("Consult_GUI") = "Edit7")
Hotkey, If, (Active_Control("Consult_GUI") = "Edit7")

List_Of_Active_Hotstrings := []
List := ""
Loop, % List_Of_Active_Hotstrings.MaxIndex()
	List.= List_Of_Active_Hotstrings[A_Index] "`n"

Loop, 4
	{
	Abbreviation_Length := 3+(A_Index-1)
	For All, Drug in Drugs
		{
		NewStr := SubStr(Drug, 1, Abbreviation_Length)
		Hotstring(":C1B0X*:" NewStr, "Drug_Menu")
		List_Of_Active_Hotstrings.Push(NewStr)
		}
	}

return

Drug_Menu:
Length := StrLen(Shortcut := SubStr(A_ThisHotkey, 9))
Gui, Drugs: Destroy
Gui, Drugs:-Caption +Toolwindow +AlwaysOnTop
Gui, Drugs:Margin, 0, 0
Gui, Drugs:Color, 0x254C5A, 0x254C5A
Gui, Drugs:font, s13 bold

Loop, Parse, Drug_List, `n
	{
	NewStr2 := RegExReplace(A_ThisHotkey, "(:C1B0X\*:)", "")
	if (NewStr2 ~= "i)" SubStr(A_LoopField, 1, Length))
		{
		Gui, Drugs:Add, Edit, cWhite vE%A_Index%, %A_LoopField%
		}
	}

CoordMode, Caret , Screen
Caret_Y := A_CaretY + 30
Gui, Drugs:Show, x%A_CaretX% y%Caret_Y% NA, Drugs
OnMessage(0x0201, "WM_LBUTTONDOWN")
return

InputHook_End(ih){
	Reason := ih.EndReason
	KeyName := ih.EndKey
	Current_String := ih.Input
	Backspace_Number := StrLen(Current_String) + 1
	if (KeyName = "Enter") && if WinExist("Drugs")
		{
		WinGetText, GUI_Text , Drugs
		GUI_Text := StrReplace(GUI_Text, "`r`n" , "")
		SendInput, {Backspace %Backspace_Number%}
		SendInput, %GUI_Text%
		Gui, Drugs: Destroy
		}
	else if (KeyName = "Space")
		Gui, Drugs: Destroy
	ih.Start()
}

InputHook_Char(ih, char){
	;Current_String := ih.Input
	;ToolTip, %String%
	if String not in List
		Gui, Drugs: Destroy
}

Backspace_Func(){
	Gui, Drugs: Destroy
}

WM_LBUTTONDOWN(){
	Global
	Drug := "{Bs " StrLen(Shortcut) "}" Drugs[SubStr(A_GuiControl,2)]
	Gui, Drugs: Destroy
	SendInput,% Drug
}

Active_Control(Window_Title){
	ControlGetFocus, OutputVar, %Window_Title%
	return OutputVar
}

Hotkey, If,
#if

The_One_True_Rick
Posts: 65
Joined: 25 May 2023, 17:14

Re: Need Help With Advanced Hotstring Display Thing  Topic is solved

Post by The_One_True_Rick » 17 Jun 2023, 15:15

Turns out the answer is just to not use hotstrings at all. Thanks Rohwedder for the gui idea, that works great. Made a few changes to it so now all options are the same size, just looks better. Also highlights the focused one under the mouse or you can use up and down arrows to select one and hit enter. This works almost perfect now. A few little glitches but overall its great. Input hook works way better than hotsrings.

Note: "Advanced Hotsring Display Thing" was my way of saying intelisense before I knew what that was. :D

Turn it on with ctrl 1 and off with ctrl 2. Try it out in notepad because it can't find the carrot position on all windows.

Code: Select all

global Drug_List_2
BackColor := "0xFF6363"
OnMessage(0x0200, "Mouse_Move")
OnMessage(0x0201, "On_Left_Click")

Medication_InputHook := InputHook("V", "{Space}{Enter}")
Medication_InputHook.OnEnd := Func("InputHook_End")
Medication_InputHook.OnChar := Func("InputHook_Char")
Medication_InputHook.KeyOpt("{Backspace}", "N")
Medication_InputHook.OnKeyDown := Func("Backspace_Func")

Drug_List =
(
Buprenorphine/Naloxone (Suboxone)
Carisoprodol (Soma)
Celecoxib (Celebrex)
Codeine
Cyclobenzaprine (Flexeril)
Diclofenac (Voltaren)
Fentanyl
Hydrocodone
Hydrocodone/APAP (Vicodin)
Ibuprofen (Advil)
Indomethacin
Lidocaine
Meloxicam (Mobic)
Methadone
Methocarbamol (Robaxin)
Morphine (MS Contin)
Naproxen (Aleve)
Oxycodone (OxyContin)
Pentosan (Elmiron)
Sumatriptan (Imitrex)
Tramadol (Ultram)
Benazepril (Lotensin)
Captopril (Capoten)
Enalapril (Vasotec)
Fosinopril (Monopril)
Lisinopril (Prinivil, Zestril)
Moexipril (Univasc)
Perindopril (Aceon)
Quinapril (Accupril)
Ramipril (Altace)
Trandolapril (Mavik)
Azilsartan (Edarbi)
Candesartan (Atacand)
Eprosartan (Teveten)
Irbesartan (Avapro)
Losartan (Cozaar)
Olmesartan (Benicar)
Telmisartan (Micardis)
Valsartan (Diovan)
Apixaban (Eliquis)
Dabigatran (Pradaxa)
Edoxaban (Savaysa)
Heparin
Rivaroxaban (Xarelto)
Warfarin (Coumadin)
Aspirin
Clopidogrel (Plavix)
Dipyridamole (Persantine)
Prasugrel (Effient)
Ticagrelor (Brilinta)
Acebutolol (Sectral)
Atenolol (Tenormin)
Betaxolol (Kerlone)
Bisoprolol/Hydrochlorothiazide (Ziac)
Bisoprolol (Zebeta)
Metoprolol (Lopressor, Toprol XL)
Nadolol (Corgard)
Propranolol (Inderal)
Sotalol (Betapace)
Carvedilol (Coreg, Coreg CR)
Labetalol (Normodyne, Trandate)
Amlodipine (Norvasc)
Diltiazem (Cardizem, Tiazac)
Felodipine (Plendil)
Nifedipine (Adalat, Procardia)
Nimodipine (Nimotop)
Nisoldipine (Sular)
Verapamil (Calan, Verelan)
Digoxin (Lanoxin)
Atorvastatin (Lipitor)
Fluvastatin (Lescol)
Lovastatin (Mevacor)
Pitavastatin (Livalo)
Pravastatin (Pravachol)
Rosuvastatin (Crestor)
Simvastatin (Zocor)
Niacin
Ezetimibe (Zetia)
Ezetimibe/Simvastatin (Vytorin)
Acetazolamide (Diamox)
Amiloride (Midamor)
Bumetanide (Bumex)
Chlorothiazide (Diuril)
Chlorthalidone (Hygroton)
Furosemide (Lasix)
Hydro-chlorothiazide (Esidrix, Hydrodiuril)
Indapamide (Lozol)
Metalozone (Zaroxolyn)
Spironolactone (Aldactone)
Torsemide (Demadex)
Isosorbide dinitrate (Isordil)
Isosorbide mononitrate (Imdur)
Hydralazine (Apresoline)
Nitroglycerin (Nitro Bid, Nitro Stat)
Minoxidil
Alprazolam (Xanax)
Chlordiazepoxide (Librium)
Clorazepate (Tranxene)
Diazepam (Valium)
Halazepam (Paxipam)
Lorzepam (Ativan)
Oxazepam (Serax)
Prazepam (Centrax)
Quazepam (Doral)
Clonazepam (Klonopin)
Zolpidem (Ambien, Edluar, Intermezzo)
Zaleplon (Sonata)
Suvorexant (Belsomra)
Ramelteon (Rozerem)
Eszopiclone (Lunesta)
Doxepine (Silenor)
Amitriptyline (Elavil)
Mirtazapine (Remeron SolTab, Remeron)
Nortriptyline (Aventyl, Pamelor)
Trazodone (Desyrel)
Citalopram (Cipramil)
Dapoxetine (Priligy)
Escitalopram (Cipralex)
Fluoxetine (Prozac, Oxactin)
Fluvoxamine (Faverin)
Paroxetine (Seroxat)
Sertraline (Lustral)
Vortioxetine (Brintellix)
Methylphenidate (Concerta, Quillivant XR, Ritalin)
Dexmethylphenidate (Focalin XR)
Atomoxetine (Strattera)
Dextroamphetamine (Dexedrine)
Amphetamine Sulfate (Evekeo)
Amphetamine/Dextroamphetamine (Adderall XR, Adderall IR)
Prednisone
Tacrolimus (Prograf)
Cyclosporine (Neoral)
Mycophenolate Mofetil (CellCept)
Imuran (Azathioprine)
Rapamune (Rapamycin, Sirolimus)
Rosiglitazone (Avandia)
Pioglitazone (Actos)
Acarbose (Precose)
Miglitol (Glyset)
Colesevelam (Welchol)
Bromocriptine (Cycloset)
Nateglinide (Starlix)
Repaglinide (Prandin)
Glimepiride (Amaryl)
Glimepiride/Pioglitazone (Duetact)
Gliclazide
Glipizide
Glipizide ER (Glipizide XL, Glucotrol XL)
Glipizide/Metformin (Metaglip)
Glyburide (Micronase, Glynase, Diabeta)
Glyburide/Metformin (Glucovance)
Metformin (Axpinet, Diagemet, Glucient, Glucophage, Metabet)
Bexaglifloxin (Brenzavvy)
Canagliflozin (Invokana)
Dapagliflozin (Farxiga)
Empagliflozin (Jardiance)
Ertugliflozin (Steglatro)
Dulaglutide (Trulicity)
Exenatide (Byetta)
Exenatide ER (Bydureon)
Liraglutide (Victoza)
Lixisenatide (Adlyxin)
Semaglutide (Ozempic)
Alogliptin (Nesina)
Linagliptin (Tradjenta)
Saxagliptin (Onglyza)
Sitagliptin (Januvia)
Teriflunomide (Aubagio)
Dimethyl Fumarate (Tecfidera)
Diroximel Fumarate (Vumerity)
Monomethyl Fumarate (Bafiertam)
Fingolimod (Gilenya)
Siponimod (Mayzent)
Ozanimod (Zeposia)
Ponesimod (Ponvory)
Amiodarone (Cordarone, Pacerone)
Flecainide (Tambocor)
Procainamide (Procan, Procanbid)
Propafenone (Rythmol)
Quinidine
Tocainide (Tonocarid)
Lamotrigine (Lamictal)
Carbamazepine (Tegretol, Curatil)
Valproate (Dyzantil, Epilim, Episenta, Epival)
Levetiracetam (Keppra, Desitrend)
Topiramate (Topamax)
Brivaracetam
)

Loop, Parse, Drug_List, `n
	{
	RegExMatch(A_LoopField, "iO)(\w+(?:(\s|\/)\w+)?)", Generic_Pat)
	Drug_Generic_Tag := Generic_Pat.Value(1)
	if (A_Index = 1)
		Drug_List_2.= Drug_Generic_Tag
	else
		Drug_List_2.= "`n" Drug_Generic_Tag
	RegExMatch(A_LoopField, "iO)(?:\()(.*)(?:\))", Brand_List_Pat)
	Current_Drug_Brand_List := Brand_List_Pat.Value(1)
	if (Current_Drug_Brand_List != "")
		{
		Brand_Array := StrSplit(Current_Drug_Brand_List , ", ")
		for each, Brand in Brand_Array
			{
			Drug_Brand_Tag := RegExReplace(A_LoopField, "(\w*(?:.\w*)?)\s\((.*)\)", Brand " ($1)")
			Drug_List_2.= "`n" Drug_Brand_Tag
			}
		}
	}

Sort, Drug_List_2, U
Drugs := StrSplit(Drug_List_2, "`n")

Drug_Menu:
Critical

EditControls := {}
Edit_Widths := []
Edit_Controls := []

Gui, Drugs_GUI: Destroy
Gui, Drugs_GUI:-Caption +Toolwindow +AlwaysOnTop +E0x08000000
Gui, Drugs_GUI:Margin, 0, 0
Gui, Drugs_GUI:Color, 0x254C5A, 0x254C5A
Gui, Drugs_GUI:font, s13 bold

global Length := StrLen(Medication_InputHook.Input)

if (Length = 0) || if (Medication_InputHook.Input = "")
	return

Loop, Parse, Drug_List_2, `n
	{
	if (Medication_InputHook.Input = SubStr(A_LoopField, 1, StrLen(Medication_InputHook.Input)))
		{
		Gui, Drugs_GUI: Add, Edit, cWhite vE%A_Index% hwndHED, %A_LoopField%
		SetFocusedBkColor(HED, BackColor)
		GuiControlGet, Edit_Hwnd, Drugs_GUI: Hwnd , E%A_Index%
		Edit_Controls.Push(Edit_Hwnd)
		GuiControlGet, Edit_Pos, Drugs_GUI: Pos , E%A_Index%
		Edit_Widths.Push(Edit_PosW)
		Highest_Number := Max(Edit_Widths*)
		for index, Edit_Control in Edit_Controls
			GuiControl, Drugs_GUI: Move, %Edit_Control%, W%Highest_Number%
		}
	}

OnMessage(0x0133, "SetFocusedBkColor")

CoordMode, Caret , Screen
Caret_Y := A_CaretY + (A_ScreenHeight/36)

if (A_CaretY != "")
	Gui, Drugs_GUI:Show, x%A_CaretX% y%Caret_Y% NA, Drugs_GUI

WinGet, Drugs_GUI_ID , ID, Drugs_GUI
GuiControl, Drugs_GUI: Focus, Edit1
return

^1::
Medication_InputHook.Start()
return

^2::
Critical, Off
Medication_InputHook.Stop()
return

InputHook_End(ih){
	KeyName := ih.EndKey
	Reason := ih.EndReason
	if (KeyName = "Enter") && if WinExist("Drugs_GUI")
		{
		ControlGetFocus, Focused_Ctrl , Drugs_GUI,
		GuiControlGet, Focused_Ctrl_Text ,Drugs_GUI: , %Focused_Ctrl%,
		SendInput, % "{Backspace " Length + 1 "}" Focused_Ctrl_Text
		}
	Gui, Drugs_GUI: Destroy
	if (Reason != "Stopped") ;so it doesnt resart every time you stop it, allows you to actually turn it off
		ih.Start()
}

InputHook_Char(ih, char){
	Current_String := ih.Input
	Loop, Parse, Drug_List_2, `n
		{
		if (Current_String = SubStr(A_LoopField, 1, StrLen(Current_String)))
			{
			gosub, Drug_Menu
			return
			}
		}
	Gui, Drugs_GUI: Destroy
}

Backspace_Func(ih, char){
	gosub, Drug_Menu
}

Active_Control(Window_Title){
	ControlGetFocus, OutputVar, %Window_Title%
	return OutputVar
}

#IfWinExist, Drugs_GUI
~LButton::
MouseGetPos, , , MouseWin, ctrl
if (MouseWin != Drugs_GUI_ID) || if (ctrl ~= "Edit\d+") = false
	Gui, Drugs_GUI: Destroy
return

Up::
GuiControlGet, Focused_Control, Drugs_GUI: FocusV
RegExMatch(Focused_Control, "iO)(\d+)", Control_Num_Pat)
Control_Num := Control_Num_Pat.Value(1)
--Control_Num
GuiControl, Drugs_GUI: Focus, E%Control_Num%
return

Down::
GuiControlGet, Focused_Control, Drugs_GUI: FocusV
RegExMatch(Focused_Control, "iO)(\d+)", Control_Num_Pat)
Control_Num := Control_Num_Pat.Value(1)
++Control_Num
GuiControl, Drugs_GUI: Focus, E%Control_Num%
return
#IfWinExist,

On_Left_Click(wParam, lParam, msg, hwnd){
	Global
	if WinExist("Drugs_GUI")
		{
		Medication_InputHook.Stop()
		ControlGetFocus, Focused_Ctrl , Drugs_GUI,
		GuiControlGet, Focused_Ctrl_Text ,Drugs_GUI: , %Focused_Ctrl%,
		SendInput, % "{Backspace " Length "}" Focused_Ctrl_Text
		Gui, Drugs_GUI: Destroy
		Medication_InputHook.Start()
		}
}

Mouse_Move(wParam, lParam, msg, hwnd){
	MouseGetPos,,,,ctrl
	GuiControlGet, CtrlHwnd, Hwnd , %ctrl%
	if (ctrl ~= "Edit\d+") && if WinExist("Drugs_GUI")
		GuiControl, Drugs_GUI: Focus, %CtrlHwnd%
}

SetFocusedBkColor(wParam := "", lParam := "", msg := "", hwnd := ""){
	Static Controls := {}
	If (msg && hwnd) ; system call: wParam = HDC, lParam = HWND
		{
		If Controls.HasKey(lParam)
			{
			If (lParam = DllCall("GetFocus", "UPtr"))
				{
				Controls[lParam, "Invalidated"] := False
				DllCall("SetBkColor", "Ptr", wParam, "UInt", Controls[lParam, "Color"])
				Return Controls[lParam, "Brush"]
				}
			 Else If !Controls[lParam, "Invalidated"]
				{
				Controls[lParam, "Invalidated"] := True
				DllCall("InvalidateRect", "Ptr", lParam, "Ptr", 0, "UInt", 1)
				}
			}
		}
	Else  ; setup call: W = HWND, lParam = color
		{
		If DllCall("IsWindow", "Ptr", wParam)
			{
			If Controls.HasKey(wParam)
				{
				DllCall("DeleteObject", "Ptr", Controls[wParam, "Brush"])
				Controls.Delete(wParam)
				}
			If (lParam <> "") && ((EditColor := SwapRB(lParam)) <> "")
				{
				Controls[wParam, "Color"] := EditColor
				Controls[wParam, "Brush"] := DllCall("CreateSolidBrush", "UInt", EditColor, "Uptr")
				Controls[wParam, "Invalidated"] := True
				}
			DllCall("RedrawWindow", "Ptr", wParam, "Ptr", 0, "Ptr", 0, "UInt", 0x0405, "UInt")
			}
		}
}

SwapRB(Color){ ; converts RGB to BGR and vice versa
   Return ((Color & 0xFF0000) >> 16) | (Color & 0x00FF00) | ((Color & 0x0000FF) << 16)
}

Post Reply

Return to “Ask for Help (v1)”