Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

Using function keys F1 to F12 as part of hotkey


  • Please log in to reply
5 replies to this topic
jonespdb
  • Members
  • 2 posts
  • Last active: Apr 20 2009 08:39 AM
  • Joined: 16 Apr 2009
Hi,

I have recently discovered AHK - excellent program!!

I am now using it to replace my previous usage of activewords. One feature I would like to implement is being able to associate a short word followed by an F-key, eg F12, with a window from which I can select some action. For example, I maight have "rep<F12>" to call up list of reports. Is this possible?

I know I can associate a single hot-key, eg #R, but I find words easier to remember.

Regards
Phil.

tonne
  • Members
  • 1654 posts
  • Last active: May 06 2014 06:22 PM
  • Joined: 06 Jun 2006
Yes, here are two suggestions:
; this is a hotstring activated with *
:*:rep*::
  msgbox rep
return

; this is a hotkey; when activated copies the text before caret
f11::
  clipboard=
  send ^+{left}^c
  clipwait,1
  msgbox %clipboard%
return


jonespdb
  • Members
  • 2 posts
  • Last active: Apr 20 2009 08:39 AM
  • Joined: 16 Apr 2009
Hi Tonne,

Thanks for tip - but I'm afraid I do not understand what you have done.

I tried both of them, and neither seems to do anything - therefore I haven't made things clear, I think.

Following is an example hotkey script - activated by #q

; Example: ListBox containing files in a directory:

sitelist = C:\_CF_CURRENT_ME\_AHK_scripts\www-site-launcher\www-site-launcher-sites.txt

gui, font, s11, Verdana  ; Set 10-point Verdana.
Gui, Add, Text,, Pick a file to launch from the list below.`nTo cancel, press ESCAPE or close this window.
Gui, Add, ListBox, vMyListBox gMyListBox w640 r19
Gui, Add, Button, Default, OK

; Change folder and wildcard pattern below to suit your preferences....
ifnotexist %sitelist%
{
	msgbox, cannot find sites file
	exitapp
}
Loop, read, %sitelist%
{
    GuiControl,, MyListBox, %A_Loopreadline%
}

Gui, Show, center autosize
return

MyListBox:
if A_GuiEvent <> DoubleClick
    return
; Otherwise, the user double-clicked a list item, so treat that the same as pressing OK.
; So fall through to the next label.
ButtonOK:
GuiControlGet, MyListBox  ; Retrieve the ListBox's current selection.
;MsgBox, 4,, Would you you like to launch the file or document below?`n`n%MyListBox%
;IfMsgBox, No
;    return
; Otherwise, try to launch it:
Run, %MyListBox%,, UseErrorLevel
if ErrorLevel = ERROR
    MsgBox Could not launch the specified file.  Perhaps it is not associated with anything.
;return

GuiClose:
GuiEscape:
ExitApp

What I want to be able to do is activate this with a word followed by a function key, eg "web" then hitting F12.

tonne
  • Members
  • 1654 posts
  • Last active: May 06 2014 06:22 PM
  • Joined: 06 Jun 2006
The hotkey approach messes with the clipboard in order to get the just typed word. The hotstring use * to activate.
A third method would be to use the Input command.
; this is a hostring activated with *
:*:web*::
	gosub SiteList
return
	
; this is a hotkey; when activated copies the text before caret
f12::
  clipboard=
  send ^+{left}^c
  clipwait,1
  if (clipboard = "web")
  	gosub SiteList
return

SiteList: ; a label used above
sitelist = C:\_CF_CURRENT_ME\_AHK_scripts\www-site-launcher\www-site-launcher-sites.txt
... the rest of your code


ManaUser
  • Members
  • 1121 posts
  • Last active: Dec 07 2016 04:24 PM
  • Joined: 24 May 2007
Obviously what you're asking is a little tricky, but here's my take on it:
SendMode Input

:*?B0:rep::
:*?B0:web::
:*?B0:spam::
Return

$F12::
If (A_TimeSincePriorHotkey < 2000 AND SubStr(A_PriorHotkey,1 , 6) = ":*?B0:")
{
   Keyword := SubStr(A_PriorHotkey, 7)
   Length := StrLen(Keyword)
   Send {BS %Length%}

   If (Keyword = "rep")
      Send representative
   If (Keyword = "web")
      Run http://google.com
   If (Keyword = "spam")
      MsgBox Oh no! Not more spam.
}
else
   Send {F12}

Though it occurs to me that doing the other way around is a bit easier:
SendMode Input

$F12::
Input Keyword, T3, {Enter} {ESC},rep,web,spam
If (ErrorLevel = "EndKey:Enter")
   Send {F12}

If (Keyword = "rep")
   Send representative
If (Keyword = "web")
   Run http://google.com
If (Keyword = "spam")
   MsgBox Oh no! Not more spam.

Return
That is you press F12 and then type something. But I can see where that might not feel as intuitive.

VxE
  • Moderators
  • 3622 posts
  • Last active: Dec 24 2015 02:21 AM
  • Joined: 07 Oct 2006
:?*B0:web::
Input, dummy, VL1T9, {F12}
If !InStr(ErrorLevel, "EndKey")
	return
SendInput, {BS 3} ; explicitly backspace this hotstring
msgbox, You typed "web[F12]"
return

Another way is to watch for the F12 key after a keyword is typed.