.NET的键盘Hook管理类,用于禁用键盘输入和切换

一、MyHook帮助类

 此类需要编写指定屏蔽的按键,灵活性差。

using System;
using System.Runtime.InteropServices;
using System.Diagnostics;
using System.Windows.Forms;
using Microsoft.Win32;namespace MyHookClass
{/// <summary>/// 类一/// </summary>public class MyHook{//消息函数的委托public delegate int HookProc(int nCode, int wParam, IntPtr lParam);static int hHook = 0;public const int WH_KEYBOARD_LL = 13;//底层键盘钩子static HookProc KeyBoardHookProcedure;//按键信息结构[StructLayout(LayoutKind.Sequential)]public class KeyBoardHookStruct{public int vkCode;public int scanCode;public int flags;public int time;public int dwExtraInfo;}//安装钩子[DllImport("user32.dll")]public static extern int SetWindowsHookEx(int idHook, HookProc lpfn, IntPtr hInstance, int threadId);//卸载钩子[DllImport("user32.dll", CharSet = CharSet.Auto, CallingConvention = CallingConvention.StdCall)]public static extern bool UnhookWindowsHookEx(int idHook);//下一个钩挂的函数[DllImport("user32.dll")]public static extern int CallNextHookEx(int idHook, int nCode, int wParam, IntPtr lParam);//返回当前线程 ID[DllImport("kernel32.dll")]public static extern int GetCurrentThreadId();//得到模块的句柄[DllImport("kernel32.dll")]public static extern IntPtr GetModuleHandle(string name);//安装钩子public static void InsertHook(){if (hHook == 0){KeyBoardHookProcedure = new HookProc(KeyBoardHookProc);hHook = SetWindowsHookEx(WH_KEYBOARD_LL,KeyBoardHookProcedure,GetModuleHandle(Process.GetCurrentProcess().MainModule.ModuleName), 0);if (hHook == 0){UnHook();throw new Exception("设置Hook失败!");}else{RegistryKey key = Registry.CurrentUser.OpenSubKey(@"Software\Microsoft\Windows\CurrentVersion\Policies\System", true);if (key == null)//如果该项不存在的话,则创建该项key = Registry.CurrentUser.CreateSubKey(@"Software\Microsoft\Windows\CurrentVersion\Policies\System");key.SetValue("DisableTaskMgr", 1, RegistryValueKind.DWord);//key.SetValue("DisableLockWorkstation", 1, RegistryValueKind.DWord);key.Close();}}}//卸载钩子public static void UnHook(){bool retKeyboard = true;if (hHook != 0){retKeyboard = UnhookWindowsHookEx(hHook);hHook = 0;}//if (!retKeyboard) throw new Exception("卸载Hook失败!");RegistryKey key = Registry.CurrentUser.OpenSubKey(@"Software\Microsoft\Windows\CurrentVersion\Policies\System", true);if (key != null){key.DeleteValue("DisableTaskMgr", false);//key.DeleteValue("DisableLockWorkstation", false);key.Close();}}//按键消息的处理函数public static int KeyBoardHookProc(int nCode, int wParam, IntPtr lParam){if (nCode >= 0){KeyBoardHookStruct kbh = (KeyBoardHookStruct)Marshal.PtrToStructure(lParam, typeof(KeyBoardHookStruct));//添加自己的判断语句,如果符合要求的按键,就 return 1; //没有判断直接 return 1;那么就屏蔽所有按键除了ctrl+alt+del//屏蔽Ctrl+Escif (kbh.vkCode == (int)Keys.Delete && (int)Control.ModifierKeys == (int)Keys.Control + (int)Keys.Alt)      //截获Ctrl+Alt+Delete{PubLibrary.WriteErrLog("1.拦截信息:Ctrl+Alt+Delete");return 1;}if (kbh.vkCode == (int)Keys.Escape){PubLibrary.WriteErrLog("2.拦截信息:Escape");return 1;}if (kbh.vkCode == 91) // 截获左win(开始菜单键) {PubLibrary.WriteErrLog("3.拦截信息:截获左win");return 1;}if (kbh.vkCode == 92)// 截获右win {PubLibrary.WriteErrLog("4.拦截信息:截获右win");return 1;}//if (kbh.vkCode == (int)Keys.L)//{//    PubLibrary.WriteErrLog("5.拦截信息:L");//    return 1;//}if (kbh.vkCode == (int)Keys.Alt){PubLibrary.WriteErrLog("6.拦截信息:Alt");return 1;}if ((int)Control.ModifierKeys == (int)Keys.Alt) //截获alt{PubLibrary.WriteErrLog("7.拦截信息:Alt");return 1;}if (kbh.vkCode == (int)Keys.Escape && (int)Control.ModifierKeys == (int)Keys.Control) //截获Ctrl+Esc {PubLibrary.WriteErrLog("8.拦截信息:Ctrl+Esc");return 1;}if (kbh.vkCode == (int)Keys.Escape && (int)Control.ModifierKeys == (int)Keys.Alt) //截获Alt+Esc {PubLibrary.WriteErrLog("9.拦截信息:Alt+Esc");return 1;}if (kbh.vkCode == (int)Keys.F4 && (int)Control.ModifierKeys == (int)Keys.Alt) //截获alt+f4 {PubLibrary.WriteErrLog("10.拦截信息:F4+Alt");return 1;}if (kbh.vkCode == (int)Keys.Tab && (int)Control.ModifierKeys == (int)Keys.Alt) //截获alt+tab{PubLibrary.WriteErrLog("10.拦截信息:alt+tab");return 1;}if (kbh.vkCode == (int)Keys.Escape && (int)Control.ModifierKeys == (int)Keys.Control + (int)Keys.Shift) //截获Ctrl+Shift+Esc{PubLibrary.WriteErrLog("11.拦截信息:Ctrl+Shift+Esc");return 1;}if (kbh.vkCode == (int)Keys.Space && (int)Control.ModifierKeys == (int)Keys.Alt) //截获alt+空格 {PubLibrary.WriteErrLog("12.拦截信息:alt+空格");return 1;}if (kbh.vkCode == 241) //截获F1 {PubLibrary.WriteErrLog("13.拦截信息:F1");return 1;}if ((int)Control.ModifierKeys == (int)Keys.Control + (int)Keys.Alt + (int)Keys.Delete)      //截获Ctrl+Alt+Delete {PubLibrary.WriteErrLog("14.拦截信息:Ctrl+Alt+Delete");return 1;}if ((int)Control.ModifierKeys == (int)Keys.Control + (int)Keys.Shift) //截获Ctrl+Shift {PubLibrary.WriteErrLog("15.拦截信息:Ctrl+Shift");return 1;}if (kbh.vkCode == (int)Keys.Space && (int)Control.ModifierKeys == (int)Keys.Control + (int)Keys.Alt) //截获Ctrl+Alt+空格 {PubLibrary.WriteErrLog("16.拦截信息:Ctrl+Alt+空格");return 1;}}return CallNextHookEx(hHook, nCode, wParam, lParam);}}
}

二、KeyboardHookLib帮助类

using System;
using System.Runtime.InteropServices;
using System.Diagnostics;
using Microsoft.Win32;namespace VendorSoftwareReleaseLW.Class
{/// <summary>/// 键盘Hook管理类/// </summary>public class KeyboardHookLib{private const int WH_KEYBOARD_LL = 13; //键盘//键盘处理事件委托 ,当捕获键盘输入时调用定义该委托的方法.private delegate int HookHandle(int nCode, int wParam, IntPtr lParam);//客户端键盘处理事件public delegate void ProcessKeyHandle(HookStruct param, out bool handle);//接收SetWindowsHookEx返回值private static int _hHookValue = 0;//勾子程序处理事件private HookHandle _KeyBoardHookProcedure;//Hook结构[StructLayout(LayoutKind.Sequential)]public class HookStruct{public int vkCode;public int scanCode;public int flags;public int time;public int dwExtraInfo;}//设置钩子[DllImport("user32.dll")]private static extern int SetWindowsHookEx(int idHook, HookHandle lpfn, IntPtr hInstance, int threadId);//取消钩子[DllImport("user32.dll", CharSet = CharSet.Auto, CallingConvention = CallingConvention.StdCall)]private static extern bool UnhookWindowsHookEx(int idHook);//调用下一个钩子[DllImport("user32.dll")]private static extern int CallNextHookEx(int idHook, int nCode, int wParam, IntPtr lParam);//获取当前线程ID[DllImport("kernel32.dll")]private static extern int GetCurrentThreadId();//Gets the main module for the associated process.[DllImport("kernel32.dll")]private static extern IntPtr GetModuleHandle(string name);private IntPtr _hookWindowPtr = IntPtr.Zero;//构造器public KeyboardHookLib() { }//外部调用的键盘处理事件private static ProcessKeyHandle _clientMethod = null;/// <summary>/// 安装勾子/// </summary>/// <param name="hookProcess">外部调用的键盘处理事件</param>public void InstallHook(ProcessKeyHandle clientMethod){_clientMethod = clientMethod;// 安装键盘钩子if (_hHookValue == 0){_KeyBoardHookProcedure = new HookHandle(OnHookProc);_hookWindowPtr = GetModuleHandle(Process.GetCurrentProcess().MainModule.ModuleName);//************************************ //键盘线程钩子 //SetWindowsHookEx( 2,KeyboardHookProcedure, IntPtr.Zero, GetCurrentThreadId()); //GetCurrentThreadId()为要监视的线程ID,你完全可以自己写个方法获取QQ的线程哦 //键盘全局钩子,需要引用空间(using System.Reflection;) //SetWindowsHookEx( 13,KeyboardHookProcedure,Marshal.GetHINSTANCE(Assembly.GetExecutingAssembly().GetModules()[0]),0); // //关于SetWindowsHookEx (int idHook, HookProc lpfn, IntPtr hInstance, int threadId)函数将钩子加入到钩子链表中,说明一下四个参数: //idHook 钩子类型,即确定钩子监听何种消息,上面的代码中设为2,即监听键盘消息并且是线程钩子,如果是全局钩子监听键盘消息应设为13, //线程钩子监听鼠标消息设为7,全局钩子监听鼠标消息设为14。 // //lpfn 钩子子程的地址指针。如果dwThreadId参数为0 或是一个由别的进程创建的线程的标识,lpfn必须指向DLL中的钩子子程。 除此以外,lpfn可 //以指向当前进程的一段钩子子程代码。钩子函数的入口地址,当钩子钩到任何消息后便调用这个函数。 // //hInstance应用程序实例的句柄。标识包含lpfn所指的子程的DLL。如果threadId 标识当前进程创建的一个线程,而且子程代码位于当前 //进程,hInstance必须为NULL。可以很简单的设定其为本应用程序的实例句柄。 // //threadedId 与安装的钩子子程相关联的线程的标识符。如果为0,钩子子程与所有的线程关联,即为全局钩子。 //************************************ _hHookValue = SetWindowsHookEx(WH_KEYBOARD_LL,_KeyBoardHookProcedure,_hookWindowPtr,0);//如果设置钩子失败.if (_hHookValue == 0){UninstallHook();}else{RegistryKey key = Registry.CurrentUser.OpenSubKey(@"Software\Microsoft\Windows\CurrentVersion\Policies\System", true);if (key == null)//如果该项不存在的话,则创建该项key = Registry.CurrentUser.CreateSubKey(@"Software\Microsoft\Windows\CurrentVersion\Policies\System");key.SetValue("DisableTaskMgr", 1, RegistryValueKind.DWord);//key.SetValue("DisableLockWorkstation", 1, RegistryValueKind.DWord);key.Close();}}}//取消钩子事件public void UninstallHook(){if (_hHookValue != 0){bool ret = UnhookWindowsHookEx(_hHookValue);if (ret) _hHookValue = 0;}RegistryKey key = Registry.CurrentUser.OpenSubKey(@"Software\Microsoft\Windows\CurrentVersion\Policies\System", true);if (key != null){key.DeleteValue("DisableTaskMgr", false);//key.DeleteValue("DisableLockWorkstation", false);key.Close();}}//钩子事件内部调用,调用_clientMethod方法转发到客户端应用。private static int OnHookProc(int nCode, int wParam, IntPtr lParam){if (nCode >= 0){//转换结构HookStruct hookStruct = (HookStruct)Marshal.PtrToStructure(lParam, typeof(HookStruct));if (_clientMethod != null){bool handle = false;//调用客户提供的事件处理程序。_clientMethod(hookStruct, out handle);if (handle) return 1; //1:表示拦截键盘,return 退出}}return CallNextHookEx(_hHookValue, nCode, wParam, lParam);}}
}

三、在WinForm中的使用

using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Data;
using System.Diagnostics;
using System.Runtime.InteropServices;
using System.Threading;
using System.Windows.Forms;
using MyHookClass;
using KeyboardHookLibClass;namespace TestForm
{public partial class LoginForm : Form{DateTime _dtNow;[DllImport("user32.dll")]private static extern IntPtr GetForegroundWindow();[DllImport("user32.dll")]private static extern bool SetForegroundWindow(IntPtr hWnd);[DllImport("user32.dll")]private static extern IntPtr FindWindow(string lpClassName, string lpWindowName);[DllImport("user32.dll")]public static extern bool SetWindowPos(IntPtr hWnd, int hWndInsertAfter, int X, int Y, int cx, int cy, int uFlags);[DllImport("user32.dll")]public static extern bool IsWindowVisible(IntPtr hWnd);//勾子管理类private KeyboardHookLib _keyboardHook = null;public delegate void ForegroundWin();private void LoginForm_Load(object sender, EventArgs e){SetHook();Thread threadForeground = new Thread(ShowWindowAsync);//threadForeground.IsBackground = true;threadForeground.Start();}private void txt_KeyDown(object sender, KeyEventArgs e){_dtNow = DateTime.Now;}private void txt_KeyUp(object sender, KeyEventArgs e){if (e.KeyCode != Keys.Enter){DateTime dtTemp = DateTime.Now;TimeSpan ts = dtTemp.Subtract(_dtNow);if (ts.Milliseconds > 65){//setTool("错误:禁止手工输入!", "N");txt.Text = "";//清空}}}private void txtID_KeyPress(object sender, KeyPressEventArgs e){if (e.KeyChar == 13){//做些操作ClearHook();}}public static void SetWindowPos(IntPtr hWnd){//0x0010为不激活窗口,这个比较关键SetWindowPos(hWnd, -1, 0, 0, 0, 0, 0x0001 | 0x0002 | 0x0010);// 0x001 | 0x002 | 0x0010| 0x040}private void ShowWindowAsync(){while (true){//高版本的这里可以直接使用Action,更简化一些//ForegroundWin d = new ForegroundWin(action);//this.Invoke(d);Action a = new Action(() => { action(); });Thread.Sleep(100);//这个时间间隔,用户基本感觉不出有切换窗体}}void action(){IntPtr hWnd = this.Handle;if (hWnd != IntPtr.Zero || GetForegroundWindow() != hWnd){//选中当前的句柄窗口SetWindowPos(hWnd);//SendKeys.SendWait(" ");}}private void ClearHook() {//取消勾子if (_keyboardHook != null) _keyboardHook.UninstallHook();//MyHook.UnHook();//ProcessMgr.ResumeWinlogon();}private void SetHook() {//安装勾子_keyboardHook = new KeyboardHookLib();_keyboardHook.InstallHook(this.OnKeyPress);//MyHook.InsertHook();//ProcessMgr.SuspendWinlogon();}/// <summary>/// 客户端键盘捕捉事件./// </summary>/// <param name="hookStruct">由Hook程序发送的按键信息</param>/// <param name="handle">是否拦截</param>public void OnKeyPress(KeyboardHookLib.HookStruct hookStruct, out bool handle){handle = false; //预设不拦截任何键if (hookStruct.vkCode == 91) // 截获左win(开始菜单键){handle = true;}if (hookStruct.vkCode == 92)// 截获右win{handle = true;}if ((int)Control.ModifierKeys == (int)Keys.Alt) //截获alt{handle = true;}//截获Ctrl+Escif (hookStruct.vkCode == (int)Keys.Escape && (int)Control.ModifierKeys == (int)Keys.Control){handle = true;}//截获alt+f4if (hookStruct.vkCode == (int)Keys.F4 && (int)Control.ModifierKeys == (int)Keys.Alt){handle = true;}//截获alt+tabif (hookStruct.vkCode == (int)Keys.Tab && (int)Control.ModifierKeys == (int)Keys.Alt){handle = true;}//截获alt+tabif (hookStruct.vkCode == (int)Keys.Escape && (int)Control.ModifierKeys == (int)Keys.Alt){handle = true;}//截获F1if (hookStruct.vkCode == (int)Keys.F1){handle = true;}//截获Ctrl+Alt+Deleteif ((int)Control.ModifierKeys == (int)Keys.Control + (int)Keys.Alt + (int)Keys.Delete){handle = true;}//如果键A~Zif (hookStruct.vkCode >= (int)Keys.A && hookStruct.vkCode <= (int)Keys.Z){//挡掉B键if (hookStruct.vkCode == (int)Keys.B)hookStruct.vkCode = (int)Keys.None; //设键为0handle = true;}Keys key = (Keys)hookStruct.vkCode;PubLibrary.WriteErrLog("你按下:" + (key == Keys.None ? "" : key.ToString()));}}
}

四、其他类

using System;
using System.Runtime.InteropServices;namespace ShareToolClass
{public class ShareTool : IDisposable{[DllImport("advapi32.dll", SetLastError = true)]static extern bool LogonUser(string pszUsername, string pszDomain, string pszPassword,int dwLogonType, int dwLogonProvider, ref IntPtr phToken);// closes open handes returned by LogonUser       [DllImport("kernel32.dll", CharSet = CharSet.Auto)]extern static bool CloseHandle(IntPtr handle);[DllImport("Advapi32.DLL")]static extern bool ImpersonateLoggedOnUser(IntPtr hToken);[DllImport("Advapi32.DLL")]static extern bool RevertToSelf();const int LOGON32_PROVIDER_DEFAULT = 0;const int LOGON32_LOGON_NEWCREDENTIALS = 9;const int LOGON32_LOGON_INTERACTIVE = 2;private bool disposed;public ShareTool(string username, string password, string ip){// initialize tokens       IntPtr pExistingTokenHandle = new IntPtr(0);IntPtr pDuplicateTokenHandle = new IntPtr(0);try{// get handle to token       bool bImpersonated = LogonUser(username, ip, password,LOGON32_LOGON_NEWCREDENTIALS, LOGON32_PROVIDER_DEFAULT, ref pExistingTokenHandle);if (bImpersonated){if (!ImpersonateLoggedOnUser(pExistingTokenHandle)){int nErrorCode = Marshal.GetLastWin32Error();throw new Exception("ImpersonateLoggedOnUser error;Code=" + nErrorCode);}}else{int nErrorCode = Marshal.GetLastWin32Error();throw new Exception("LogonUser error;Code=" + nErrorCode);}}finally{// close handle(s)       if (pExistingTokenHandle != IntPtr.Zero)CloseHandle(pExistingTokenHandle);if (pDuplicateTokenHandle != IntPtr.Zero)CloseHandle(pDuplicateTokenHandle);}}protected virtual void Dispose(bool disposing){if (!disposed){RevertToSelf();disposed = true;}}public void Dispose(){Dispose(true);}}
}
using System;
using System.Diagnostics;
using System.Runtime.InteropServices;namespace ProcessMgrClass
{class ProcessMgr{/// <summary>/// The process-specific access rights./// </summary>[Flags]public enum ProcessAccess : uint{/// <summary>/// Required to terminate a process using TerminateProcess./// </summary>Terminate = 0x1,/// <summary>/// Required to create a thread./// </summary>CreateThread = 0x2,/// <summary>/// Undocumented./// </summary>SetSessionId = 0x4,/// <summary>/// Required to perform an operation on the address space of a process (see VirtualProtectEx and WriteProcessMemory)./// </summary>VmOperation = 0x8,/// <summary>/// Required to read memory in a process using ReadProcessMemory./// </summary>VmRead = 0x10,/// <summary>/// Required to write to memory in a process using WriteProcessMemory./// </summary>VmWrite = 0x20,/// <summary>/// Required to duplicate a handle using DuplicateHandle./// </summary>DupHandle = 0x40,/// <summary>/// Required to create a process./// </summary>CreateProcess = 0x80,/// <summary>/// Required to set memory limits using SetProcessWorkingSetSize./// </summary>SetQuota = 0x100,/// <summary>/// Required to set certain information about a process, such as its priority class (see SetPriorityClass)./// </summary>SetInformation = 0x200,/// <summary>/// Required to retrieve certain information about a process, such as its token, exit code, and priority class (see OpenProcessToken, GetExitCodeProcess, GetPriorityClass, and IsProcessInJob)./// </summary>QueryInformation = 0x400,/// <summary>/// Undocumented./// </summary>SetPort = 0x800,/// <summary>/// Required to suspend or resume a process./// </summary>SuspendResume = 0x800,/// <summary>/// Required to retrieve certain information about a process (see QueryFullProcessImageName). A handle that has the PROCESS_QUERY_INFORMATION access right is automatically granted PROCESS_QUERY_LIMITED_INFORMATION./// </summary>QueryLimitedInformation = 0x1000,/// <summary>/// Required to wait for the process to terminate using the wait functions./// </summary>Synchronize = 0x100000}[DllImport("ntdll.dll")]private static extern uint NtResumeProcess([In] IntPtr processHandle);[DllImport("ntdll.dll")]private static extern uint NtSuspendProcess([In] IntPtr processHandle);[DllImport("kernel32.dll", SetLastError = true)]private static extern IntPtr OpenProcess(ProcessAccess desiredAccess,bool inheritHandle,int processId);[DllImport("kernel32.dll", SetLastError = true)][return: MarshalAs(UnmanagedType.Bool)]private static extern bool CloseHandle([In] IntPtr handle);public static void SuspendProcess(int processId){IntPtr hProc = IntPtr.Zero;try{// Gets the handle to the ProcesshProc = OpenProcess(ProcessAccess.SuspendResume, false, processId);if (hProc != IntPtr.Zero)NtSuspendProcess(hProc);}finally{// Don't forget to close handle you created.if (hProc != IntPtr.Zero)CloseHandle(hProc);}}public static void ResumeProcess(int processId){IntPtr hProc = IntPtr.Zero;try{// Gets the handle to the ProcesshProc = OpenProcess(ProcessAccess.SuspendResume, false, processId);if (hProc != IntPtr.Zero)NtResumeProcess(hProc);}finally{// Don't forget to close handle you created.if (hProc != IntPtr.Zero)CloseHandle(hProc);}}public static void SuspendWinlogon(){Process[] processes = Process.GetProcesses();foreach (Process process in processes){if (process.ProcessName == "winlogon"){SuspendProcess(process.Id);}}}public static void ResumeWinlogon(){Process[] processes = Process.GetProcesses();foreach (Process process in processes){Console.WriteLine(process.ProcessName);if (process.ProcessName == "winlogon"){ResumeProcess(process.Id);}}}}
}

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.rhkb.cn/news/145773.html

如若内容造成侵权/违法违规/事实不符,请联系长河编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

回归预测 | MATLAB实现RUN-XGBoost龙格库塔优化极限梯度提升树多输入回归预测

回归预测 | MATLAB实现RUN-XGBoost多输入回归预测 目录 回归预测 | MATLAB实现RUN-XGBoost多输入回归预测预测效果基本介绍程序设计参考资料 预测效果 基本介绍 MATLAB实现RUN-XGBoost多输入回归预测&#xff08;完整源码和数据&#xff09; 1.龙格库塔优化XGBoost&#xff0c;…

【Redis】redis基本数据类型详解(String、List、Hash、Set、ZSet)

目录 RedisString(字符串)List(列表)Hash(字典)Set(集合)ZSet(有序集合) Redis Redis有5种基本的数据结构&#xff0c;分别为&#xff1a;string&#xff08;字符串&#xff09;、list&#xff08;列表&#xff09;、set&#xff08;集合&#xff09;、hash&#xff08;哈希&a…

ahk系列——ahk_v2实现win10任意界面ocr

前言&#xff1a; 不依赖外部api接口&#xff0c;界面简洁&#xff0c;翻译快速&#xff0c;操作简单&#xff0c; 有网络就能用 、还可以把ocr结果非中文翻译成中文、同样可以识别中英日韩等60多个国家语言并翻译成中文&#xff0c;十分的nice 1、所需环境 windows10及其以上…

Linux学习记录——삼십일 socket编程---TCP套接字

文章目录 TCP套接字简单通信1、服务端1、基本框架2、获取连接 2、客户端3、多进程4、多线程5、线程池6、简单的日志系统7、守护进程8、其它 TCP套接字简单通信 本篇gitee 学习完udp套接字通信后&#xff0c;再来看TCP套接字。 四个文件tcp_server.hpp&#xff0c; tcp_serve…

Linux常见操作命令(1)

​ 前言&#xff1a;作者也是初学Linux&#xff0c;可能总结的还不是很到位 ♈️今日夜电波&#xff1a;达尔文—林俊杰 0:30━━━━━━️&#x1f49f;──────── 4:06 &#x1f504; ◀️ …

Redis与分布式-分布式锁

接上文 Redis与分布式-集群搭建 1.分布式锁 为了解决上述问题&#xff0c;可以利用分布式锁来实现。 重新复制一份redis&#xff0c;配置文件都是刚下载时候的不用更改&#xff0c;然后启动redis服务和redis客户。 redis存在这样的命令&#xff1a;和set命令差不多&#xff0…

Windows上安装 Go 环境

一、下载go环境 下载go环境&#xff1a;Go下载官网链接找到自己想下载的版本&#xff0c;点击下载&#xff0c;比如我这是windows64位的&#xff0c;我就直接点击最新的。 二、安装go环境 双击下载的.msi文件 next next 他默认的是c盘&#xff0c;你自己可以改&#xff0c;然…

Redis优化

Redis优化 一、Sring数据类型1.1、 概述1.2、 set/get/append/strlen命令1.3、 incr/decr/incrby/decrby 命令1.4、 getset命令1.5、 setex命令1.6、 setnx命令1.7、 mset/mget/msetnx命令 二、List数据类型2.1、 概述2.2、 lpush/lpushx/lrange命令2.3、 lpop/llen命令2.4、 l…

phpstudy_pro高效率建一个属于自己的网站

1.下载phpStudy_32 2.下载wordpress-6.3-zh_CN 安装好phpstudy后启动phpstudy中对应的服务&#xff0c;并在网站中配置好对一个的应用的路径 ps:根目录中的路径是你想要通过phpstudy部署应用的路径 这里以wordpress为例 将下载wordpress的压缩包解压后&#xff0c;需要修改…

VS+Qt+C++ GDAL读取tif图像数据显示

程序示例精选 VSQtC GDAL读取tif图像数据显示 如需安装运行环境或远程调试&#xff0c;见文章底部个人QQ名片&#xff0c;由专业技术人员远程协助&#xff01; 前言 这篇博客针对《VSQtC GDAL读取tif图像数据显示》编写代码&#xff0c;代码整洁&#xff0c;规则&#xff0c;…

A. Sequence with Digits

题目&#xff1a;样例&#xff1a; 输入 8 1 4 487 1 487 2 487 3 487 4 487 5 487 6 487 7输出 42 487 519 528 544 564 588 628 思路&#xff1a; 暴力模拟题&#xff0c;看这数据范围&#xff0c;有些人可能会被唬住&#xff0c;以为是高精度或者容易超时&#xff0c;实际上…

Docker 自动化部署(实践)

常用命令 docker search jenkins查看需要的jenkins镜像源 docker pull jenkins/jenkins 拉取jenkins镜像 docker images查看下载的镜像源 docker ps 查看包含启动以及未启动的容器 docker ps -a查看启动的容器 docker rm 容器id/容器名称 删除容器 docker rm -f 容器id/容器名…

一站式企业协同研发云——云效

一站式企业协同研发云——云效 文章目录 一站式企业协同研发云——云效什么是云效云效的作用云效使用说明公司领导操作步骤项目创建者或项目组长操作步骤项目上线部署 什么是云效 云效是一种基于云计算技术的软件研发与交付管理平台&#xff0c;旨在提高团队的协作效率和软件交…

Redis与分布式-集群搭建

接上文 Redis与分布式-哨兵模式 1. 集群搭建 搭建简单的redis集群&#xff0c;创建6个配置&#xff0c;开启集群模式&#xff0c;将之前配置过的redis删除&#xff0c;重新复制6份 针对主节点redis 1&#xff0c;redis 2&#xff0c;redis 3都是以上修改内容&#xff0c;只是…

求各区域热门商品Top3 - HiveSQL

背景&#xff1a;这是尚硅谷SparkSQL练习题&#xff0c;本文用HiveSQL进行了实现。 数据集&#xff1a;用户点击表&#xff0c;商品表&#xff0c;城市表 题目: ① 求每个地区点击量前三的商品&#xff1b; ② 在①的基础上&#xff0c;求出每个地区点击量前三的商品后&a…

【Linux】【网络】传输层协议:TCP

文章目录 TCP 协议1. TCP 协议段格式2. TCP 报头解析3. TCP 的可靠性4. 面向字节流5. 粘包问题6. 连接队列维护 TCP 的 确认应答机制TCP 的 超时重传机制TCP 的 三次握手TCP 的 四次挥手setsockopt 函数&#xff1a;设置套接字选项&#xff0c;解决 TIME_WAIT 状态引起的 bind …

【Python】基于OpenCV人脸追踪、手势识别控制的求实之路FPS游戏操作

【Python】基于OpenCV人脸追踪、手势识别控制的求实之路FPS游戏操作 文章目录 手势识别人脸追踪键盘控制整体代码附录&#xff1a;列表的赋值类型和py打包列表赋值BUG复现代码改进优化总结 py打包 视频&#xff1a; 基于OpenCV人脸追踪、手势识别控制的求实之路FPS游戏操作 手…

小谈设计模式(7)—装饰模式

小谈设计模式&#xff08;7&#xff09;—装饰模式 专栏介绍专栏地址专栏介绍 装饰模式装饰模式角色Component&#xff08;抽象组件&#xff09;ConcreteComponent&#xff08;具体组件&#xff09;Decorator&#xff08;抽象装饰器&#xff09;ConcreteDecorator&#xff08;具…

玩转数据-大数据-Flink SQL 中的时间属性

一、说明 时间属性是大数据中的一个重要方面&#xff0c;像窗口&#xff08;在 Table API 和 SQL &#xff09;这种基于时间的操作&#xff0c;需要有时间信息。我们可以通过时间属性来更加灵活高效地处理数据&#xff0c;下面我们通过处理时间和事件时间来探讨一下Flink SQL …

解决前端二进制流下载的文件(例如:excel)打不开的问题

1. 现在后端请求数据后&#xff0c;返回了一个二进制的数据&#xff0c;我们要把它下载下来。 这是响应的数据&#xff1a; 2. 这是调用接口的地方&#xff1a; uploadOk(){if(this.files.length 0){return this.$Message.warning("请选择上传文件&#xff01;&#xff…