12

For example , you push Ctrl+V and insert the buffer content into the window. How can I create my own hotkeys like that? Sorry for noobish question.

Fabrizio
  • 7,603
  • 6
  • 44
  • 104
  • Its not a noobish question, but we need more detail. Are you asking for your own use, for instance, assign a hot-key to launch firefox? Or for a windows application you are writing. – Alan Jun 10 '09 at 17:00
  • That depends on what you want to do with the hotkey. For e.g. do you a hotkey to launch a program? Other than that, I think you'd need a customized program to perform the hot-key "registration" for you. – kizzx2 Jun 10 '09 at 17:00
  • 1
    The example you give, Ctrl+V is not a hotkey but a command accelerator. Hotkeys generally refer to globally registered keyboard shortcuts whereas command accelerators are per process keyboard shortcuts. – sean e Jun 10 '09 at 17:04
  • Fine question, one I'm sure I had at one time. +1 – Copas Jun 10 '09 at 17:39

7 Answers7

11

A great way to do this quickly and easily is with a script language that focuses on macro programming. My favorite is AutoIt as it says in a clip from the AutoIt help file...

AutoIt was initially designed for PC "roll out" situations to reliably automate and configure thousands of PCs. Over time it has become a powerful language that supports complex expressions, user functions, loops and everything else that veteran scripters would expect.

Writing a hotkey application in AutoIt couldn't be easier. For example lets say for some reason (to obscure to mention) you would like Alt+Q to react as number pad key 7 in a particular situation possibly so you don't have to reach across the keyboard for it. Here's some code that does that...

Func _num7()
    Send("{numpad7}")
EndFunc

HotKeySet("!{q}","_num7")

While 1
    sleep(10)
WEnd

If that's not straight forward enough the AutoIt help file and forums are very helpful. Not to mention a (very) few AutoIt developers are available on SO if you end up with any AutoIt specific questions.

In the example above lets say you only wanted the hotkeys to be active when a particular application was in use so as to not interfere with other hotkeys. This code would accomplish just that.

; The comment character in AutoIt is ;
Local $inTargetProg = False

Func _num7()
    Send("{numpad7}")
EndFunc

While 1
    If WinActive("Target Application Window Title") and Not $inTargetProg Then
        HotKeySet("!{q}","_num7") ; binds Alt+Q to the _num7() function
        $inWC3 = True
    EndIf

    If Not WinActive("Target Application Window Title") and $inTargetProg Then
        HotKeySet("!{q}") ; UnBind the hotkey when not in use
        $inWC3 = False
    EndIf

    sleep(5)
WEnd
Fabrizio
  • 7,603
  • 6
  • 44
  • 104
Copas
  • 5,921
  • 5
  • 29
  • 43
  • 1
    Wonderful! hope you enjoy AutoIt! – Copas Jun 10 '09 at 17:38
  • Yes, AutoIT does rock! Here's a link to the AutoIt function HotKeySet: http://www.autoitscript.com/autoit3/docs/functions/HotKeySet.htm – Jeff May 30 '11 at 13:18
  • @Copas Thank you very much for this answer. Now I can start writing my hot key program for dota :) – rana Dec 02 '11 at 15:09
  • Yeah it works perfectly but i really think it's a dirty work, like using a dead loop to keep the program running rather than using service or hook to finish it....Any better solutions? – AuBee Dec 26 '16 at 21:01
5

Per-process keyboard shortcuts like Ctrl+V are usually defined in a resource (.rc) file and loaded via the Win32 API LoadAccelerators.

Windows-wide keyboard shortcuts (hotkeys) are registered using the Win32 API RegisterHotKey.

Fabrizio
  • 7,603
  • 6
  • 44
  • 104
sean e
  • 11,792
  • 3
  • 44
  • 56
5

I've been using AutoHotkey at work for the best part of a year now.

I just save the following file in my Windows Startup folder.

keyboard_shortcuts.ahk

#SingleInstance force
#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.
Menu, Tray, Icon, Shell32.dll, 44

; Starting Directory for cmd.exe
EnvGet, HOMEDRIVE, HOMEDRIVE
EnvGet, HOMEPATH, HOMEPATH

#i:: Run, notepad
#f:: Run, firefox
#c:: Run, cmd /k, %HOMEDRIVE%%HOMEPATH%
#m:: Run, mailto:
#b:: Run, mailto:boss@mycompany.com

"#b" means Winkey+B

"Run, mailto:boss@mycompany.com" open a black email to my boss.

#b:: Run, mailto:boss@mycompany.com
Fabrizio
  • 7,603
  • 6
  • 44
  • 104
2

Simple script with windows with no third party software required.Just save as .vbs file and double click

currentDirectory = left(WScript.ScriptFullName,(Len(WScript.ScriptFullName))-(len(WScript.ScriptName)))

Set objShell = WScript.CreateObject("WScript.Shell")
Set lnk = objShell.CreateShortcut(currentDirectory  & "search.LNK") 
lnk.TargetPath = currentDirectory  & "search.bat"
lnk.Arguments = ""
lnk.Description = "Abiram's search"
lnk.HotKey = "SHIFT+CTRL+C"
lnk.WindowStyle = "7"
lnk.WorkingDirectory = currentDirectory
lnk.Save
'Clean up 
Set lnk = Nothing

Change the lnk.TargetPath to include your exe file or batch file to be called.

Sergey K.
  • 24,894
  • 13
  • 106
  • 174
Abiram
  • 171
  • 1
  • 4
2

You can create a simple hotkey in Windows by creating a shortcut and then assign a shortcut key to it. I have done this for launching some command line apps with parameters. The following link explains using a shortcut key to an app to mute the volume:Mute

Just replace the Target: and Shortcut Key: in the shortcut properties with whatever you need for your purposes.

Louis Davis
  • 774
  • 7
  • 8
1

Ok...the easiest way, for example On you desktop, you can use accelerated command by right click the icon > properties > shortcut key; Click on the empty space and it will seem like nothing happens, but this is when you assign your "hotkey" I used Shift+1 and whenever I combine Shift+1 Firefox opens.

Fabrizio
  • 7,603
  • 6
  • 44
  • 104
0

First, welcome to Stack Overflow!

Second, this is a program by program thing. The only reason that Ctrl+C or Ctrl+V works across different programs is because there is operating system support for the clipboard and many programs follow the convention of using Ctrl+C or Ctrl+V. In your own programs, you can bind the keys however you like! For more details, we'll need more information about your program.

If you want to make actual hotkeys for Windows itself, I'm not sure how (nor if you are able) to make your own hotkeys. You might want to look into AutoIt, which is a free program that can do all sorts of things you might want to use a hotkey for, such as automatically clicking through menus, etc.

Fabrizio
  • 7,603
  • 6
  • 44
  • 104
samoz
  • 56,849
  • 55
  • 141
  • 195
  • Thanks! The result I need is the following : you run the program and whenever you are using new hotkeys(for example, you are writing in the pad or anywhere else), the program executes what is prescripted for that hotkey. –  Jun 10 '09 at 17:16
  • Well you want global hotkeys then. You want to use the RegisterHotKey in the Win32 API as sean e said below. – samoz Jun 10 '09 at 17:21