Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 339293
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T10:30:34+00:00 2026-05-12T10:30:34+00:00

I am using a .dll called Kiosk in my application which is resonsible for

  • 0

I am using a .dll called Kiosk in my application which is resonsible for disabling some keyboard keys. I am doing like this…

using Kiosk;
-----

public static Kiosk.Kiosk KIOSK = new Kiosk.Kiosk();

-----

static void Main()
{
    KIOSK.Disable();
}

I call like this in Program.cs and all other page loads of my form. I want to call this function only once, globally. Where to call that to disable my keyboard keys through out my application.

I thought Program.cs is the correct place to call the method globally. But dosent work if i call the method only there.

Please help. Thanks.

The Kiosk.dll comprises this VB code :
This code is working perfectly. I am calling the Disable() method in my application like above.

Option Explicit On 
Option Strict On

Imports Microsoft.Win32
Imports System.Runtime.InteropServices

Public Class Kiosk
    Implements IDisposable

#Region "IDisposable"

    ' Implementing IDisposable since it might be possible for
    ' someone to forget to cause the unhook to occur.  I didn't really
    ' see any problems with this in testing, but since the SDK says
    ' you should do it, then here's a way to make sure it will happen.

    Public Overloads Sub Dispose() Implements IDisposable.Dispose
        Dispose(True)
        GC.SuppressFinalize(Me)
    End Sub

    Protected Overridable Overloads Sub Dispose(ByVal disposing As Boolean)
        If disposing Then
            ' Free other state (managed objects).
        End If
        If m_hookHandle <> 0 Then
            UnhookWindowsHookEx(m_hookHandle)
            m_hookHandle = 0
        End If
        If m_taskManagerValue > -1 Then
            EnableTaskManager()
        End If
    End Sub

    Protected Overrides Sub Finalize()
        Dispose(False)
    End Sub

#End Region

    Private Delegate Function LowLevelHookDelegate(ByVal code As Integer, ByVal wParam As Integer, ByRef lParam As KeyboardLowLevelHookStruct) As Integer

    Private Const Hc_Action As Integer = 0
    Private Const WindowsHookKeyboardLowLevel As Integer = 13
    Private Const LowLevelKeyboardHfAltDown As Integer = &H20

    Private Enum WindowsMessage
        KeyDown = &H100
        KeyUp = &H101
        SystemKeyDown = &H104
        SystemKeyUp = &H105
    End Enum

    Private Enum Vk
        Tab = &H9
        Escape = &H1B
        Shift = &H10
        Control = &H11
        Menu = &H12         ' ALT key.
        Alt = &H12
        Pause = &H13
        LeftWindows = &H5B  ' Left Windows key (Microsoft® Natural® keyboard).
        RightWindows = &H5C ' Right Windows key (Natural keyboard).
        Applications = &H5D ' Applications key (Natural keyboard).
    End Enum

    Private Structure KeyboardLowLevelHookStruct
        Public VirtualKeyCode As Integer
        Public ScanCode As Integer
        Public Flags As Integer
        Public Time As Integer
        Public ExtraInfo As UInt32
    End Structure

    Private Declare Function SetWindowsHookEx Lib "user32" Alias "SetWindowsHookExA" (ByVal hook As Integer, ByVal address As LowLevelHookDelegate, ByVal [mod] As Integer, ByVal threadId As Integer) As Integer
    Private Declare Function CallNextHookEx Lib "user32" (ByVal handle As Integer, ByVal code As Integer, ByVal wParam As Integer, ByVal lParam As KeyboardLowLevelHookStruct) As Integer
    Private Declare Function UnhookWindowsHookEx Lib "user32" (ByVal handle As Integer) As Integer
    Private Declare Function GetAsyncKeyState Lib "user32" (ByVal virtualKey As Integer) As Integer

    Private m_hookHandle As Integer

    Private Function LowLevelHook(ByVal code As Integer, ByVal wParam As Integer, ByRef lParam As KeyboardLowLevelHookStruct) As Integer

        If code = Hc_Action Then

            If (wParam = WindowsMessage.KeyDown) OrElse _
               (wParam = WindowsMessage.SystemKeyDown) OrElse _
               (wParam = WindowsMessage.KeyUp) OrElse _
               (wParam = WindowsMessage.SystemKeyUp) Then

                'Dim alt As Boolean = (GetAsyncKeyState(Vk.Alt) And &H8000) = &H8000
                'Dim shift As Boolean = (GetAsyncKeyState(Vk.Shift) And &H8000) = &H8000
                Dim control As Boolean = (GetAsyncKeyState(Vk.Control) And &H8000) = &H8000

                Dim suppress As Boolean

                ' CTRL+ESC
                If control AndAlso lParam.VirtualKeyCode = Vk.Escape Then
                    suppress = True
                End If

                ' ALT+TAB
                'If (lParam.Flags And LowLevelKeyboardHfAltDown) = LowLevelKeyboardHfAltDown AndAlso lParam.VirtualKeyCode = Vk.Tab Then
                '  suppress = True
                'End If

                ' ALT+ESC
                If (lParam.Flags And LowLevelKeyboardHfAltDown) = LowLevelKeyboardHfAltDown AndAlso lParam.VirtualKeyCode = Vk.Escape Then
                    suppress = True
                End If

                ' Left Windows button.
                If lParam.VirtualKeyCode = Vk.LeftWindows Then
                    suppress = True
                End If

                ' Right Windows button.
                If lParam.VirtualKeyCode = Vk.RightWindows Then
                    suppress = True
                End If

                ' Applications button.
                If lParam.VirtualKeyCode = Vk.Applications Then
                    suppress = True
                End If

                If suppress Then
                    Return 1
                End If

            End If

            Return CallNextHookEx(m_hookHandle, code, wParam, lParam)

        End If

    End Function

    Public Sub Disable()
        If m_hookHandle = 0 Then
            m_hookHandle = SetWindowsHookEx(WindowsHookKeyboardLowLevel, AddressOf LowLevelHook, Marshal.GetHINSTANCE(System.Reflection.Assembly.GetExecutingAssembly.GetModules()(0)).ToInt32, 0)
        End If
    End Sub

    Public Sub Enable()
        If m_hookHandle <> 0 Then
            UnhookWindowsHookEx(m_hookHandle)
            m_hookHandle = 0
        End If
    End Sub

End Class
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T10:30:35+00:00Added an answer on May 12, 2026 at 10:30 am

    If you just want to call it once, “globally”, you can do it like so:

    class SomeMainClassThatAlwaysIsUsed
    {
        static SomeMainClassThatAlwaysIsUsed () {
            new Kiosk.Kiosk().Disable();
        }
    }
    

    That uses the static initialiser, which will run once, per AppDomain.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I’m having some difficulties while trying to consume an unmanaged-code dll from my application
I'm creating a .NET DLL that acts as a wrapper using PInvoke on an
Using C#, Visual Studio 2010. There is a namespace called System.Web.Mvc documented on MSDN.
Hi I am using a 3rd party library in my iPhone application that uses
For my CMS application I'm writing a DLL that I will include into my
I'm currently working on a program in C# WPF. I use an external dll
I am interacting with a custom COM component called CSCCOM in my c# project.
I've been using S#arp and have updated the Generate method in AutoPersistenceModelGenerator to work
Morning. Issue: I have a class called Reports. Two constructors. One allows no parameters,
I had written a code snippet in VC++. However, I cannot continue rest of

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.