Identify Special key keycode

馋奶兔 提交于 2019-12-25 16:59:17

问题


I am using a windows 8 laptop. My old laptop had a key combo, fn+f5, which would make the computer go to sleep. My new laptop has a power button on the side that acts like the one on your phone, it puts the PC to standby/sleep. But i don't like hardware buttons because they wear out. I plugged in a logitech keyboard that has a dedicated key with the power button symbol and when you press it, it does the same thing. (i did not install any software or drivers btw, just plugged it in) My goal is to use autohotkey to assign a key combo to send the same keycode. There are baked-in some windows functions (I don't know what to call them. Shell commands?) that are supposed to put the PC to sleep but they always put it into hibernation or shut it down, not what i want, which is why i am resorting to this. Does anyone know how to intercept keycodes or something?


回答1:


Paste this into a text file and save as .AHK and run.

#SingleInstance Force
#InstallKeybdHook
#InstallMouseHook
NP:="Untitled - Notepad"

IfWinExist, % NP
WinActivate
else
IfWinNotExist, % NP
Run, Notepad.exe,, UseErrorLevel, nPID
nPID=%nPID%
if (ErrorLevel){
    MsgBox, there is a problem
}else{
    ToolTip, Notepad running as PID: %nPID%
    Sleep, 1000
    ToolTip
}
WinActivate, % NP
WinWaitActive, % NP
Send, {Raw}Hello %A_UserName%,`n`nRight click on the H icon on your traybar`ngoto -> "Open" ->          "View" - > "Key History and Script Info"`n`nThis area shows you your past keypresses. =]`n`n-islanq
return

AHK Literature on Special Keys - Link

AHK Literature on InstallKeyboardHook - Link



来源:https://stackoverflow.com/questions/23897387/identify-special-key-keycode

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!