简体   繁体   English

检查组合键按下 NSIS

[英]Check Key Combo Pressed NSIS

I'm trying to figure out how to get my NSIS installer to respond to key presses.我试图弄清楚如何让我的 NSIS 安装程序响应按键。 I thought I would get my answer here , but the link referenced in the answer isn't working.我以为我会在这里得到答案,但答案中引用的链接不起作用。

This is what I've tried:这是我试过的:

!include WinMessages.nsh

Section
  DetailPrint "Starting"
  SendMessage $HWNDPARENT ${WM_SETHOTKEY} 1616 0
  Sleep 3000
  SendMessage $HWNDPARENT ${WM_GETHOTKEY} 0 0 $R0
  Pop $R1
  StrCpy $R2 "$$R0 = $R0"
  StrCpy $R2 "$R2$\n$$R1 = $R1"
  IntCmp $R1 0 not_pressed pressed
  
  pressed:
  StrCpy $R2 "$R2$\nPressed"
  Goto end
  
  not_pressed:
  StrCpy $R2 "$R2$\nNot pressed"
  Goto end
  
  end:
  MessageBox MB_OK $R2
SectionEnd

I tried running the installer and pressing CTRL+ALT+P and various points, but I never get anything from the stack.我尝试运行安装程序并按 CTRL+ALT+P 和各种键,但我从未从堆栈中得到任何东西。 I tried setting the hotkey to ${HOTKEYF_ALT} , but that didn't make a difference (eventually I'd like to map to CTRL+ALT+F12, but I just want a key combo that works for now).我尝试将热键设置为${HOTKEYF_ALT} ,但这并没有什么不同(最终我想将 map 设置为 CTRL+ALT+F12,但我只想要一个目前有效的组合键)。

Edit:编辑:

I also tried replacing Sleep 3000 with我还尝试将Sleep 3000替换为

  StrCpy $R3 0
  DetailPrint "$$R3 = $R3"
  IntOp $R3 $R3 + 1
  IntCmp $R3 3000 0 -2

just in case that line was causing a problem.以防那条线引起问题。 It didn't help.它没有帮助。

The page on the forum you linked to used a custom version of the nsDialogs plug-in, it does not support this by default.您链接到的论坛上的页面使用了自定义版本的 nsDialogs 插件,默认情况下不支持此功能。

NSIS does not have support for global hot-keys because they are not common in installers. NSIS 不支持全局热键,因为它们在安装程序中并不常见。

A global hot-key to focus the installer window is possible but not really that useful:一个全局热键来聚焦安装程序 window 是可能的,但并不是那么有用:

!include WinMessages.nsh

Function .onGuiInit
!define /IfNDef HOTKEYF_CONTROL 2
!define /IfNDef HOTKEYF_ALT 4
!define /IfNDef VK_F12 0x7b
IntOp $0 ${HOTKEYF_CONTROL} | ${HOTKEYF_ALT}
IntOp $0 $0 << 8
IntOp $0 $0 | ${VK_F12}
SendMessage $hWndParent ${WM_SETHOTKEY} $0 0
FunctionEnd

The NsKeyHook plug-in can handle the WM_CHAR and WM_KEYUP messages so you will be able to perform custom actions when certain keys are pressed but this will only work when a window you have hooked in the installer has focus. NsKeyHook 插件可以处理 WM_CHAR 和 WM_KEYUP 消息,因此您可以在按下某些键时执行自定义操作,但这仅在您在安装程序中挂接的 window 具有焦点时才有效。

If you don't mind gross hacks, I invented a way to have a global hot-key on a custom page:如果您不介意粗暴的黑客攻击,我发明了一种在自定义页面上使用全局热键的方法:

!include WinMessages.nsh
!include nsDialogs.nsh


Function onNotifyHack
Pop $0 ; HWND
Pop $1 ; Code
Pop $2 ; pNMH
!define /IfNDef NM_FIRST 0
!define /IfNDef /Math NM_SETFOCUS ${NM_FIRST} - 7
${If} $1 = ${NM_SETFOCUS}
    System::Call 'USER32::SetForegroundWindow(p$hWndParent)'
    MessageBox MB_OK "Hotkey pressed!"
${EndIf}
FunctionEnd

Function myPage
nsDialogs::Create 1018
Pop $0

${NSD_CreateLabel} 0 0 100% 12u "Press Ctrl+Alt+F12"
Pop $0

nsDialogs::CreateControl "SysListView32" ${WS_VISIBLE}|${WS_CHILD} ${WS_EX_TOOLWINDOW} 0 0 0 0 ""
Pop $1
System::Call 'USER32::SetParent(p$1,p0)'
${NSD_RemoveStyle} $1 ${WS_CHILD}
${NSD_OnNotify} $1 onNotifyHack
SendMessage $1 ${WM_SETHOTKEY} 0x067b 0
Push $1

nsDialogs::Show
Pop $1
SendMessage $1 ${WM_CLOSE} "" ""
FunctionEnd

Page Custom myPage
Page InstFiles

Section 
SectionEnd

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM