1

i am using Office 2016 and i want to do a PowerPoint presentation where you can't exit slide show just with hitting ESC key, so you can interact with slides only by your mouse ( or eventually exit it with a key combination but not by just clicking ESC ). Kiosk mode do most of work but still ESC is available. I know about NoEsc add-in but it does not work for me. It just not showing me that menu in Ribbon or elsewhere, but other add-ins do and they appear in Add-ins tab next to View tab in. So i found a code on other website for keyboard disabling macro but it works only on 32-bit and can't run on 64-bit. Im not a coder so i need a little help how can i make it work on 64-bit or 32+64-bit.

Here is an original code from website:

Option Explicit
 
'Esc Disable Key
Private Const WH_KEYBOARD_LL = 13&
Private Const HC_ACTION = 0&
Private Const VK_ESCAPE = &H1B
 
Private Type KBDLLHOOKSTRUCT
  vkCode As Long
  scanCode As Long
  flags As Long
  time As Long
  dwExtraInfo As Long
End Type
   Dim Response As Integer
 
Private Declare Function SetWindowsHookEx Lib "user32" Alias "SetWindowsHookExA" (ByVal idHook As Long, ByVal lpfn As Long, ByVal hmod As Long, ByVal dwThreadId As Long) As Long
Public Declare Function UnhookWindowsHookEx Lib "user32" (ByVal hHook As Long) As Long
Private Declare Sub CopyMemory Lib "Kernel32" Alias "RtlMoveMemory" (pDest As Any, pSource As Any, ByVal cb As Long)
Private Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Long) As Integer
Public m_hDllKbdHook As Long
 
 Public Sub hookup()
 Call UnhookWindowsHookEx(m_hDllKbdHook)
 m_hDllKbdHook = SetWindowsHookEx(WH_KEYBOARD_LL, AddressOf LowLevelKeyboardProc, App.hInstance, 0&)
 End Sub
 
Public Function LowLevelKeyboardProc(ByVal nCode As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Static kbdllhs As KBDLLHOOKSTRUCT
 
If nCode = HC_ACTION Then
      Call CopyMemory(kbdllhs, ByVal lParam, Len(kbdllhs))
     If (kbdllhs.vkCode = VK_ESCAPE) Then
       LowLevelKeyboardProc = 1
     End If
End If
End Function

And Here is what i did so far:

  1. Change App.hInstance to 0&, because i got an error that App. is not defined.
 Public Sub hookup()
 Call UnhookWindowsHookEx(m_hDllKbdHook)
 m_hDllKbdHook = SetWindowsHookEx(WH_KEYBOARD_LL, AddressOf LowLevelKeyboardProc, App.hInstance, 0&)
 End Sub

To

 Public Sub hookup()
 Call UnhookWindowsHookEx(m_hDllKbdHook)
 m_hDllKbdHook = SetWindowsHookEx(WH_KEYBOARD_LL, AddressOf LowLevelKeyboardProc, 0&, 0&)
 End Sub
  1. Added PtrSafe next to all Declare But then mismatch appeared here and highlight "AddressOf LowLevelKeyboardProc"
 Public Sub hookup()
 Call UnhookWindowsHookEx(m_hDllKbdHook)
 m_hDllKbdHook = SetWindowsHookEx(WH_KEYBOARD_LL, AddressOf LowLevelKeyboardProc, 0&, 0&)
 End Sub

So i changed "lpfn As Long" to "lpfn As LongPtr" and then mismatch error is gone.

Private Declare PtrSafe Function SetWindowsHookEx Lib "user32" Alias "SetWindowsHookExA" (ByVal idHook As Long, ByVal lpfn As Long, ByVal hmod As Long, ByVal dwThreadId As Long) As Long

To

Private Declare PtrSafe Function SetWindowsHookEx Lib "user32" Alias "SetWindowsHookExA" (ByVal idHook As Long, ByVal lpfn As LongPtr, ByVal hmod As Long, ByVal dwThreadId As Long) As Long

But the problem is, even if i got rid of all error messages in macro editor and i can run this macro with no troubles seems like it does nothing during slide show. ESC key is still working even after running it by Macro Window or clicking action button for "Run macro" during show.

Macros are set to Always Enabled ( Lowest security mode ) in Office Options and presentation is saved as (.ppsm), so macro-enabled format.

Here is my full modified code:


Option Explicit
 
'Esc Disable Key
Private Const WH_KEYBOARD_LL = 13&
Private Const HC_ACTION = 0&
Private Const VK_ESCAPE = &H1B
 
Private Type KBDLLHOOKSTRUCT
  vkCode As Long
  scanCode As Long
  flags As Long
  time As Long
  dwExtraInfo As Long
End Type
   Dim Response As Integer
 
Private Declare PtrSafe Function SetWindowsHookEx Lib "user32" Alias "SetWindowsHookExA" (ByVal idHook As Long, ByVal lpfn As LongPtr, ByVal hmod As Long, ByVal dwThreadId As Long) As Long
Public Declare PtrSafe Function UnhookWindowsHookEx Lib "user32" (ByVal hHook As Long) As Long
Private Declare PtrSafe Sub CopyMemory Lib "Kernel32" Alias "RtlMoveMemory" (pDest As Any, pSource As Any, ByVal cb As Long)
Private Declare PtrSafe Function GetAsyncKeyState Lib "user32" (ByVal vKey As Long) As Integer
Public m_hDllKbdHook As Long
 
 Public Sub hookup()
 Call UnhookWindowsHookEx(m_hDllKbdHook)
 m_hDllKbdHook = SetWindowsHookEx(WH_KEYBOARD_LL, AddressOf LowLevelKeyboardProc, 0&, 0&)
 End Sub
 
Public Function LowLevelKeyboardProc(ByVal nCode As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Static kbdllhs As KBDLLHOOKSTRUCT
 
If nCode = HC_ACTION Then
      Call CopyMemory(kbdllhs, ByVal lParam, Len(kbdllhs))
     If (kbdllhs.vkCode = VK_ESCAPE) Then
       LowLevelKeyboardProc = 1
     End If
End If
End Function

Thank you, and sorry for my bad english :)

BigBen
  • 46,229
  • 7
  • 24
  • 40
velir
  • 13
  • 2

1 Answers1

0

This used to be a big problem when people were deep diving into Excel API functions. Luckily this website has a lot of what you need all in one spot:

https://jkp-ads.com/Articles/apideclarations.asp

It's pretty much what you need : )

Peyter
  • 474
  • 3
  • 14
  • Thank you Peyter, website you sent here should be very helpful, but as i said i know nothing about coding and it will take me months to understand what that website says to me. I literally putted LongPtr everywhere and hoped that is enough to work :/. Dont know what exactly i need to change in above code. – velir Jul 09 '20 at 08:19
  • What exactly is the reasoning and use-case behind your request? I'm just wondering, if its this complex, maybe there's a better way? I'm imagining you are doing some kind of web based training or something but using PPT? If I understood your use case, I might be able to suggest a more streamlined approach – Peyter Jul 10 '20 at 02:48
  • I am using PPT for creating interactive applications ( quizzes, interactive projects and even games/minigames with mouse using ). PPT is easy and fast for doing this and i like the way of doing it, because its just my small hobby now. I want these projects to behave a little bit like a real applications so its not so obvious that its just a regular presentation. Its not like i'm making it for job or for someone else. I'm doing it just for creativity in free time "making complex things using basic tools" and sometimes i need ----> – velir Jul 10 '20 at 15:29
  • ----> somehow disable ESC key so you can't quit it by just clicking ESC and you need procced/exit only with mouse or eventually close it with key combination, thats the only thing i need because coding is my Achilles' heel and I spent many hours to figured it out with no success. I am a 2d/3d artist, working as interior archviz and product viz so i can easily do any graphic content but codding... never had time to learn it. I know i know, there are many programs where you can do apps/games or something else, but i choosed PPT in free time, because why not. – velir Jul 10 '20 at 15:30
  • Its easy, effective and you can do many creative graphic/animated things with it and also its just getting dusty on my system, because I barely used office before. – velir Jul 10 '20 at 15:30
  • And that is my motivation you asked about :) – velir Jul 10 '20 at 15:31
  • Well this should be closed then and marked as answered then. You're not using Stack Overflow for the correct reasons. Sometimes people will give you an idea or help with errors by providing edited coded. But the answer to your question is what I posted. you found the code to perform the function. Now you need to either learn how to adapt it within Microsoft's guidelines for converting 32 bit api to 64 bit api code, or pay someone to do the job. I'm not trying to be mean or anything, I just want you to understand what Stack Overflow is and isn't. – Peyter Jul 10 '20 at 17:49
  • I understood you. I will mark it as answered and thank you for answer. By the way do you know any websites where coders are doing these things ( fixing / converting code ) on demand? For pay of course. Thank you :) – velir Jul 11 '20 at 17:14
  • You could try experts exchange or like fiverr. idk man it seems like a lot. Can you use this add-in on the workstations? https://answers.microsoft.com/en-us/msoffice/forum/all/disabling-the-esc-key-during-a-ppt-show/63541337-b076-44c7-b4ee-299adf10a28f the whole request seems like SAW II to me > _ > – Peyter Jul 11 '20 at 18:16
  • Yes i saw this before, but the problem is this add-in didnt work in my 2016 office, but when i tried on my old laptop with office 2007 it worked. And the guy there didnt say if he got it run or not, he just had same problem. – velir Jul 12 '20 at 15:20
  • 1
    Yea, i found some interesting offers on fiverr, thanks :) – velir Jul 12 '20 at 15:23