Lock screen made html element not work normally.Cefsharp.WinForms

32 views
Skip to first unread message

Rang Chao

unread,
May 21, 2015, 6:05:12 AM5/21/15
to cefs...@googlegroups.com
Hello, everyone, I add a lock-screen feature to my winform program which build with Cefsharp. I found that when i lock screen, the html element "select" would not work normally, when i unlock it, then the "select" element worked correctly. Anyone can help me? or solve this problem?

Part of lock-screen code is below:
       
       
//Lock_SomeKey(true) will lock screen.
       
public bool Lock_SomeKey(bool isLock)
       
{
           
if (isLock)
           
{
               
if (this.m_lHookID == IntPtr.Zero)
               
{
                   
IntPtr pInstance = Win32Lib.GetModuleHandle(Process.GetCurrentProcess().MainModule.ModuleName);
                   
Win32Lib.hookproc = new HookProc(LowLevelKeyboardProc);
                    m_lHookID
= Win32Lib.SetWindowsHookEx(
                       
(int)HookType.WH_KEYBOARD_LL,
                       
Win32Lib.hookproc,
                        pInstance
,
                       
0);

                   
if (m_lHookID == IntPtr.Zero)
                   
{
                       
this.Lock_SomeKey(false);
                       
return false;
                   
}
               
}
               
return true;
           
}
           
else
           
{
               
bool result = true;
               
if (this.m_lHookID != IntPtr.Zero)
               
{
                    result
= Win32Lib.UnhookWindowsHookEx(m_lHookID);
                   
this.m_lHookID = IntPtr.Zero;
               
}
               
return result;
           
}
       
}
       
private int LowLevelKeyboardProc(int nCode, int wParam, IntPtr lParam)
       
{
            KBDLLHOOKSTRUCT m
= (KBDLLHOOKSTRUCT)Marshal.PtrToStructure(lParam, typeof(KBDLLHOOKSTRUCT));
           
if (nCode == 0)
           
{
               
switch (((Keys)m.vkCode))
               
{
                   
case Keys.LWin:
                   
case Keys.RWin:
                   
case Keys.Delete:
                   
case Keys.Tab:
                   
case Keys.Escape:
                   
case Keys.F4:
                   
case Keys.Control:
                   
case Keys.Alt:
                   
case Keys.Shift:
                       
return 1;
               
}
           
}
           
return 0;
       
}


Bill Tutt

unread,
May 21, 2015, 10:12:11 AM5/21/15
to cefs...@googlegroups.com
I don't know if this is the cause of your problem, but you are never calling CallNextHookEx in your LowLevelKeyboardProc function.
Hooking Chromium with this hook proc sounds like you're just asking for trouble. (Especially since you lock on Tab and Escape.)

The other thing that seems very odd is that you're installing a global hook for all running Windows applications in your Windows Desktop.
Unless you're a kiosk this seems wrong as well.

And of course the friendly reminder: Your thread that calls this MUST service these windows message queue delivered hook requests VERY quickly, (I think the default is something less than 5 seconds)
otherwise the OS will revoke your hook and it won't be called again. When I needed to install a global keyword accelerator for a external USB device that pretended to be a keyword, we called SetWindowHookEx from
a thread whose ONLY job was to service the hook requests. (Since for various reasons too much work got done on the main UI thread against best practice of UI applications.)

I hope this helps,
Bill

Rang Chao

unread,
May 21, 2015, 9:58:38 PM5/21/15
to cefs...@googlegroups.com
Ok, thanks, I will try what you said. Appreciate your help.

在 2015年5月21日星期四 UTC+8下午10:12:11,Bill Tutt写道:

Rang Chao

unread,
May 21, 2015, 10:43:49 PM5/21/15
to cefs...@googlegroups.com
Additional information:
1.What I said "not work normally" means that when screen been locked, I click the "select" html element, it will not pop up down-list, but when I unlocked screen, it works correctly.
2."Webbrowser" works correctly when I lock screen by this way.(I know webbrowser and cef are two things).

No matter how, I will check my code first to avoid problems from myself.
Sincerely expect your help.


在 2015年5月21日星期四 UTC+8下午10:12:11,Bill Tutt写道:
I don't know if this is the cause of your problem, but you are never calling CallNextHookEx in your LowLevelKeyboardProc function.
Reply all
Reply to author
Forward
0 new messages