当前位置:首页 » 网页前端 » 抢cdk脚本
扩展阅读
webinf下怎么引入js 2023-08-31 21:54:13
堡垒机怎么打开web 2023-08-31 21:54:11

抢cdk脚本

发布时间: 2023-05-22 03:08:38

A. 求一个去除字符串中汉字的脚本.要多少分你随便开

以前收藏过一段剪切板相关的代码,现在改动了一下,能满足你的要求,C#的

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;
using System.Diagnostics;
using System.Windows.Forms;
using System.Text.RegularExpressions;
namespace ClipboardTool
{
public class ClipboardHelper
{
#region 调用Windows API
private delegate IntPtr LowLevelKeyboardProc(int nCode, IntPtr wParam, IntPtr lParam);
[DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
private static extern IntPtr SetWindowsHookEx(int idHook, LowLevelKeyboardProc lpfn, IntPtr hMod, uint dwThreadId);
[DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
[return: MarshalAs(UnmanagedType.Bool)]
private static extern bool UnhookWindowsHookEx(IntPtr hhk);
[DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
private static extern IntPtr CallNextHookEx(IntPtr hhk, int nCode, IntPtr wParam, IntPtr lParam);
[DllImport("kernel32.dll", CharSet = CharSet.Auto, SetLastError = true)]
private static extern IntPtr GetMoleHandle(string lpMoleName);
#endregion
private const int WH_KEYBOARD_LL = 13;
private const int WM_KEYDOWN = 0x0100;
private static LowLevelKeyboardProc proc = HookCallback;
private static IntPtr hookID = IntPtr.Zero;
public static void RunHook()
{
hookID = SetHook(proc);
}
public static void UnHook()
{
UnhookWindowsHookEx(hookID);
}
private static IntPtr SetHook(LowLevelKeyboardProc proc)
{
using (Process curProcess = Process.GetCurrentProcess())
{
using (ProcessMole curMole = curProcess.MainMole)
{
return SetWindowsHookEx(WH_KEYBOARD_LL, proc, GetMoleHandle(curMole.MoleName), 0);
}
}
}
private static IntPtr HookCallback(int nCode, IntPtr wParam, IntPtr lParam)
{
if (nCode >= 0 && wParam == (IntPtr)WM_KEYDOWN)
{
Keys key = (Keys)Marshal.ReadInt32(lParam);
//按下Ctrl+V粘贴数据
if (Control.ModifierKeys == Keys.Control && key == Keys.V)
{
//获得剪切板数据
string dataText = Clipboard.GetText(TextDataFormat.UnicodeText);
//过滤掉汉字
dataText = Regex.Replace(dataText, @"[\u4e00-\u9fa5]+", "");
//重新设置剪切板数据
DataObject dataObject = new DataObject();
dataObject.SetData(DataFormats.Text, true, dataText);
Clipboard.SetDataObject(dataObject, true);
}
}
return CallNextHookEx(hookID, nCode, wParam, lParam);
}
}
}

使用的话,可以建个窗体、或控制台或其他,此处以窗体为例:
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
ClipboardHelper.RunHook();
}
}

运行后,在ctrl+v粘贴的时候就会过滤掉汉字了