1e56f6e6d3
- Refactoring Projects in the solution
118 lines
3.7 KiB
C#
118 lines
3.7 KiB
C#
using CefSharp;
|
|
using System.Windows.Forms;
|
|
|
|
namespace CMS_Client.Browser_Tools
|
|
{
|
|
class CefBrowserKeyHandler : IKeyboardHandler
|
|
{
|
|
//Const value of F1..F12 Keys
|
|
const int KeyF1 = 112;
|
|
const int KeyF2 = 113;
|
|
const int KeyF3 = 114;
|
|
const int KeyF4 = 115;
|
|
const int KeyF5 = 116;
|
|
const int KeyF6 = 117;
|
|
const int KeyF7 = 118;
|
|
const int KeyF8 = 119;
|
|
const int KeyF9 = 120;
|
|
const int KeyF10= 121;
|
|
const int KeyF11= 122;
|
|
const int KeyF12= 123;
|
|
const int KeyShift = 16;
|
|
const int KeyCtrl = 17;
|
|
const int KeyAlt = 18;
|
|
|
|
//Check Hotkey Pressed
|
|
bool AltPressed = false;
|
|
bool ShiftPressed = false;
|
|
bool CtrlPressed = false;
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
#region GLOBAL_METHODS
|
|
|
|
//Metod called by Browser when a key is pressed
|
|
public bool OnKeyEvent(IWebBrowser browserControl, IBrowser browser, KeyType type, int windowsKeyCode, int nativeKeyCode, CefEventFlags modifiers, bool isSystemKey)
|
|
{
|
|
//Check only if it a Key-Down event
|
|
if(type == KeyType.KeyDown || type == KeyType.RawKeyDown)
|
|
{
|
|
//Elaborates Hotkeys
|
|
KeyDwHotkeys(windowsKeyCode);
|
|
|
|
//Filter the FKey only if is with ALT key
|
|
if(AltPressed)
|
|
{
|
|
//Do things different by F Keys
|
|
switch (windowsKeyCode)
|
|
{
|
|
//F1 -> Go to Back page
|
|
case KeyF1: browser.GoBack(); break;
|
|
|
|
//F2 -> Go to Next page
|
|
case KeyF2: browser.GoForward(); break;
|
|
|
|
//F5 -> Reload this page
|
|
case KeyF5: browser.Reload(true); break;
|
|
|
|
//F12 -> Show Dev Tools
|
|
case KeyF12: browser.ShowDevTools(); break;
|
|
|
|
//F4 -> Exit application
|
|
case KeyF4: Application.Exit(); break;
|
|
|
|
}
|
|
return true;
|
|
}
|
|
|
|
}
|
|
|
|
//Check only if it a Key-Up event
|
|
else if (type == KeyType.KeyUp)
|
|
|
|
//Elaborates Hotkeys
|
|
KeyUpHotkeys(windowsKeyCode);
|
|
|
|
return false;
|
|
}
|
|
|
|
|
|
|
|
//Metod called by Browser when a key is pre-pressed
|
|
public bool OnPreKeyEvent(IWebBrowser browserControl, IBrowser browser, KeyType type, int windowsKeyCode, int nativeKeyCode, CefEventFlags modifiers, bool isSystemKey, ref bool isKeyboardShortcut)
|
|
{
|
|
return false;
|
|
}
|
|
|
|
#endregion
|
|
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
#region PRIVATE_CUSTOM_METHODS
|
|
|
|
private void KeyDwHotkeys(int windowsKeyCode)
|
|
{
|
|
if (windowsKeyCode == KeyShift)
|
|
ShiftPressed = true;
|
|
else if(windowsKeyCode == KeyCtrl)
|
|
CtrlPressed = true;
|
|
else if (windowsKeyCode == KeyAlt)
|
|
AltPressed = true;
|
|
}
|
|
|
|
|
|
|
|
private void KeyUpHotkeys(int windowsKeyCode)
|
|
{
|
|
if (windowsKeyCode == KeyShift)
|
|
ShiftPressed = false;
|
|
else if (windowsKeyCode == KeyCtrl)
|
|
CtrlPressed = false;
|
|
else if (windowsKeyCode == KeyAlt)
|
|
AltPressed = false;
|
|
}
|
|
|
|
#endregion
|
|
|
|
}
|
|
} |