Sign in to follow this  
Followers 0
bobneumann

Hotkeyset for specific app

4 posts in this topic

I want to set 3 hotkeys. 2 (ctrl-p and F2) are active whenever the window title begins with "nextgen EMR"

One ("t") is only active if the title contains "(T)oday" as the last 7 characters.

What I have works, but I'm wondering if I'm hammering my cpu needlessly. Is there a better way to do this?

#NoTrayIcon
#include <Misc.au3>
_Singleton("NGHotkeys")
Opt("WinTitleMatchMode", 2)
HotKeySet("{F2}", "ClosePatient")
HotKeySet("^p", "FilePrint")


While 1
    if WinActive ( "(T)oday" ) then 
    HotKeySet("t", "Today")
Else
    HotKeySet("t")
    Sleep(250)
    endif
WEnd
Func ClosePatient()
    Opt("WinTitleMatchMode", 1)
    if WinActive ( "NextGen EMR:") then
    send("!f")
    send("{DOWN}")
    send("o")
Else
    HotKeySet("{F2}")
    send("{F2}")
    HotKeySet("{F2}", "ClosePatient")
endif
Opt("WinTitleMatchMode", 2)
EndFunc
Func FilePrint()
    Opt("WinTitleMatchMode", 1)
    if WinActive ( "NextGen EMR:") then
    send("!f")
    send("{DOWN}")
    send("p")
Else
    HotKeySet("^p")
    send("^p")
    HotKeySet("^p", "FilePrint")
endif
Opt("WinTitleMatchMode", 2)
EndFunc
Func Today()
    $today = string(@mon)&string(@mday)&string(@year)
    send("{ESC}")
    send("{DEL}")
    send("{DEL}")
    send("{DEL}")
    send("{DEL}")
    send("{DEL}")
    send("{DEL}")
    send("{DEL}")
    send("{DEL}")
    send($today)
EndFunc
oÝ÷ زØbH§Ê&zØb bëayú%"î´"µ©òmëmz°'w¥Ø^²W§nujwZvXzví¹ÒZÊxz­¢­ê¢é]#û!¢é]"Ê&z0¶©jYm·d{+¶È§¶ayƬzËZµéاrêÚºÚ"µÍÓÕ^RXÛÛÚ[ÛYH   ÓZØË]LÉÝÂÔÚ[Û]Û   ][ÝÓÒÝÙ^É][ÝÊBÛØ[ ÌÍØÛÚÈHYX[XJ  ÌÎN×ØÜXÚÙÌÎNËL
BÝÙ^TÙ]
    ][ÝÞÑI][ÝË ][ÝÐÛÜÙT]Y[    ][ÝÊBÝÙ^TÙ]
    ][Ý×  ][ÝË  ][ÝÑ[T[   ][ÝÊBÚ[HBÛYLBÑ[[ÈØÜXÚÙ
BSÜ
    ][ÝÕÚ[]SX]Ú[ÙI][ÝËBÙ[XÝØÙHÚ[XÝ]J   ][ÝÊ
[Ù^I][ÝÈ
HS  ÌÍØÛÚÈH   ÌÍØÛÚÈHBÝÙ^TÙ]
    ][ÝÝ  ][ÝË  ][ÝÕÙ^I][ÝÊBØÙHÝÚ[XÝ]J    ][ÝÊ
[Ù^I][ÝÈ
HS  ÌÍØÛÚÈHB  ÌÍØÛÚÈHÝÙ^TÙ]
    ][ÝÝ  ][ÝÊB[Ù[XÝÜ
    ][ÝÕÚ[]SX]Ú[ÙI][ÝËJB[[Â

Any help at all greatly appreciated.

Share this post


Link to post
Share on other sites



I want to set 3 hotkeys. 2 (ctrl-p and F2) are active whenever the window title begins with "nextgen EMR"

One ("t") is only active if the title contains "(T)oday" as the last 7 characters.

What I have works, but I'm wondering if I'm hammering my cpu needlessly. Is there a better way to do this?

#NoTrayIcon
#include <Misc.au3>
_Singleton("NGHotkeys")
Opt("WinTitleMatchMode", 2)
HotKeySet("{F2}", "ClosePatient")
HotKeySet("^p", "FilePrint")
While 1
    if WinActive ( "(T)oday" ) then 
    HotKeySet("t", "Today")
Else
    HotKeySet("t")
    Sleep(250)
    endif
WEnd
Func ClosePatient()
    Opt("WinTitleMatchMode", 1)
    if WinActive ( "NextGen EMR:") then
    send("!f")
    send("{DOWN}")
    send("o")
Else
    HotKeySet("{F2}")
    send("{F2}")
    HotKeySet("{F2}", "ClosePatient")
endif
Opt("WinTitleMatchMode", 2)
EndFunc
Func FilePrint()
    Opt("WinTitleMatchMode", 1)
    if WinActive ( "NextGen EMR:") then
    send("!f")
    send("{DOWN}")
    send("p")
Else
    HotKeySet("^p")
    send("^p")
    HotKeySet("^p", "FilePrint")
endif
Opt("WinTitleMatchMode", 2)
EndFunc
Func Today()
    $today = string(@mon)&string(@mday)&string(@year)
    send("{ESC}")
    send("{DEL}")
    send("{DEL}")
    send("{DEL}")
    send("{DEL}")
    send("{DEL}")
    send("{DEL}")
    send("{DEL}")
    send("{DEL}")
    send($today)
EndFunc

Any help at all greatly appreciated.

Didn't quite get the purpose of your code. Mind explain it bit more in detail?

Share this post


Link to post
Share on other sites

Didn't quite get the purpose of your code. Mind explain it bit more in detail?

This hotkey application runs all the time in the background. However, the hotkeys should only cause an action (launch a function) in certain circumstances:

1: ctrl-p and F2 should cause an action if the active window title begins with: "Nextgen EMR"

2: The "t" key should cause an action if the active window ends with the text "(T)oday"

All other times, ctrl-p, F2, or "t" should behave normally

The While 1 loop is keeping the application active all the time. The application works. However, the application is constantly checking the active window, and setting or unsetting a hotkey state every 250 milliseconds. It seems to me that the function I posted in the second bit of code may accomplish the same purpose with lesser load on the cpu. But I don't really know.

I'm hoping an expert may recognize the better code path and point it out to me....

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

depending on the situation you could always have the hotkey active except the function it calls checks to see if the windows exists, If they dont the function does nothing.

If you must disable them when the window is not active, there's not to much you could do other than checking the title every so often like you do... if you know some events that cause the window to change titles you may be able to hook those events and disable/enable the hotkey accordingly

Edited by evilertoaster

Share this post


Link to post
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
Sign in to follow this  
Followers 0