当前位置:  编程技术>.net/c#/asp.net
本页文章导读:
    ▪实现一个属于自己的按键精灵        有点标题党的感觉~~这东西充其量只能说是按键辅助工具,和大名鼎鼎的按键精灵比起来实在是小巫见大巫了。  前两天放假无聊,天气太冷不想出门,玩起了很多年前玩过的一款游戏.........
    ▪wpf 扩展标记应用 数据类型转      总是忘记语法,复制下来记录一下。 <TextBox Grid.Column="1" Text="{Binding Path=(ListBox.SelectedValue).(DoMain:GroupModel.RowID),ElementName=mylistbox}"             &nbs.........
    ▪C# out和ref关键字      using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading.Tasks;namespace study{ public class Program { /// <summary> /// ref关键字可以让一个值类型的输入按引用传.........

[1]实现一个属于自己的按键精灵
    来源:    发布时间: 2013-10-22

  有点标题党的感觉~~这东西充其量只能说是按键辅助工具,和大名鼎鼎的按键精灵比起来实在是小巫见大巫了。

  前两天放假无聊,天气太冷不想出门,玩起了很多年前玩过的一款游戏:骑士。太久没玩,手指灵活度不够,玩的是一塌糊涂。于是想起了大名鼎鼎的按键精灵,下载,写脚本,再上游戏,解放了双手的感觉就是不一样,轻松+惬意。今天是新年上班第一天,比较有空,想起来这件事,秉承重复造轮子的指导方针,经过一下午的google,大概功能已经写好,能够满足骑士中战士这个职业最基本的需求。以下是代码:

public class hook
{
// Fields
private static int hHook;
private HookProc KeyBoardHookProcedure;

static Dictionary<string, Thread> dict = new Dictionary<string, Thread>();

// Methods
static hook() { }
public hook() { }
[DllImport("user32.dll", CharSet = CharSet.Auto, ExactSpelling = true)]
public static extern IntPtr GetForegroundWindow();
[DllImport("user32.dll", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Auto)]
public static extern int CallNextHookEx(int idHook, int nCode, IntPtr wParam, IntPtr lParam);
[DllImport("USER32.DLL")]
public static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
[DllImport("kernel32.dll", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Auto)]
private static extern IntPtr GetModuleHandle(string lpModuleName);
public void Hook_Clear()
{
bool flag = true;
if (hHook != 0)
{
flag = UnhookWindowsHookEx(hHook);
hHook = 0;
}
if (!flag)
{
throw new Exception("取消hook失败!");
}
}
public void Hook_Start()
{
if (hHook == 0)
{
this.KeyBoardHookProcedure = new HookProc(hook.KeyBoardHookProc);
hHook = SetWindowsHookEx(13, this.KeyBoardHookProcedure, GetModuleHandle(Process.GetCurrentProcess().MainModule.ModuleName), 0);
if (hHook == 0)
{
MessageBox.Show("设置Hook失败!");
this.Hook_Clear();
}
}
}
[DllImport("User32.dll")]
public static extern void keybd_event(byte bVk, byte bScan, int dwFlags, int dwExtraInfo);

public static void 战士抖杀()
{
while (true)
{
byte num1 = (byte)Keys.E;
keybd_event(num1, 0, 0, 0);
Thread.Sleep(100);
keybd_event(num1, 0, 2, 0);
Thread.Sleep(100);
keybd_event(num1, 0, 0, 0);
Thread.Sleep(100);
keybd_event(num1, 0, 2, 0);
Thread.Sleep(100);
byte num2 = (byte)Keys.D4;
keybd_event(num2, 0, 0, 0);
Thread.Sleep(100);
keybd_event(num2, 0, 2, 0);
Thread.Sleep(100);
keybd_event(num1, 0, 0, 0);
Thread.Sleep(100);
keybd_event(num1, 0, 2, 0);
Thread.Sleep(100);
keybd_event(num1, 0, 0, 0);
Thread.Sleep(100);
keybd_event(num1, 0, 2, 0);
Thread.Sleep(100);
byte num4 = (byte)Keys.R;
keybd_event(num4, 0, 0, 0);
Thread.Sleep(100);
keybd_event(num4, 0, 2, 0);
Thread.Sleep(100);
}
}

public static int KeyBoardHookProc(int nCode, IntPtr wParam, IntPtr lParam)
{
KeyBoardHookStruct input = (KeyBoardHookStruct)Marshal.PtrToStructure(lParam, typeof(KeyBoardHookStruct));

if (input.vkCode == (int)Keys.F11)
{
IntPtr ptr = GetForegroundWindow();
if (ptr != IntPtr.Zero)
{
if (dict.Count < 1)
{
ThreadStart threadStart = new ThreadStart(战士抖杀);
Thread thread = new Thread(threadStart);
thread.Start();
dict.Clear();
dict.Add("战士抖杀", thread);
}
}
return 1;
}
else if (input.vkCode == (int)Keys.F12)
{
foreach (var th in dict)
{
Thread thread = th.Value;
if (thread != null && thread.IsAlive)
{
if (!thread.Join(3))
{
thread.Abort();
}
}
}
dict.Clear();
}
return CallNextHookEx(hHook, nCode, wParam, lParam);
}
[DllImport("USER32.DLL")]
public static extern bool SetForegroundWindow(IntPtr hWnd);
[DllImport("user32.dll", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Auto)]
public static extern int SetWindowsHookEx(int idHook, HookProc lpfn, IntPtr hInstance, int threadId);
[DllImport("user32.dll", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Auto)]
public static extern bool UnhookWindowsHookEx(int idHook);

// Nested Types
public delegate int HookProc(int nCode, IntPtr wParam, IntPtr lParam);

[StructLayout(LayoutKind.Sequential)]
public class KeyBoardHookStruct
{
public int vkCode;
public int scanCode;
public int flags;
public int time;
public int dwExtraInfo;
public KeyBoardHookStruct() { }
}
}

  

本文链接


    
[2]wpf 扩展标记应用 数据类型转
    来源:    发布时间: 2013-10-22

总是忘记语法,复制下来记录一下。

<TextBox Grid.Column="1" Text="{Binding Path=(ListBox.SelectedValue).(DoMain:GroupModel.RowID),ElementName=mylistbox}"
               IsReadOnly="True" Width="100" HorizontalAlignment="Left" VerticalAlignment="Center"/>
      <ListBox  x:Name="mylistbox" Grid.Row="2" Grid.ColumnSpan="2" SelectionMode="Single" IsSynchronizedWithCurrentItem="True"
                  ItemsSource="{Binding}">
          <ListBox.Template>
              <ControlTemplate>
                  <ScrollViewer HorizontalScrollBarVisibility="Disabled" VerticalScrollBarVisibility="Auto" >
                     <WrapPanel Orientation="Horizontal" IsItemsHost="True"/>
                  </ScrollViewer>
              </ControlTemplate>
          </ListBox.Template>
          <ListBox.ItemContainerStyle>
              <Style TargetType="ListBoxItem">
                  <EventSetter Event="ListBoxItem.PreviewMouseDoubleClick"
                               Handler="ListBoxItemDoubleClick" />
              </Style>
          </ListBox.ItemContainerStyle>
          <ListBox.ItemTemplate>
              <DataTemplate DataType="{x:Type DoMain:GroupModel}">
                  <Grid >
                      <Grid.RowDefinitions>
                          <RowDefinition Height="60"/>
                          <RowDefinition/>
                      </Grid.RowDefinitions>
                      <Image Source="{Binding Ico,Mode=OneWay,Converter={StaticResource imageConverter}}"/>
                      <Label Grid.Row="1" Content="{Binding GroupName}" />
                  </Grid>
              </DataTemplate>
          </ListBox.ItemTemplate>
      </ListBox>

本文链接


    
[3]C# out和ref关键字
    来源:    发布时间: 2013-10-22
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace study
{
public class Program
{
/// <summary>
/// ref关键字可以让一个值类型的输入按引用传递
/// </summary>
private static void refFunction(int x,ref int a)
{
a = a * x;
}
/// <summary>
/// out关键字的使用
/// 使用out关键字,输入参数str在传递给outKeyWord()方法前不必进行初始化,如果没有关键字,是无法编译的
/// </summary>
private static void outKeyWord(out string str)
{
//输出参数str在方法返回前必须被赋值
str = "a string";
}
static void Main(string[] args)
{
//***********ref关键字的使用
int x = 12, a = 5;
Console.WriteLine(a);//输出:5
refFunction(x, ref a);
Console.WriteLine(a);//输出:60

//***********out关键字的使用
string str;//不必初始化
outKeyWord(out str);//输出:a string
Console.WriteLine(str);
Console.ReadKey();

}
}
}

 原创文章,转载请注明出处:http://www.cnblogs.com/hongfei/archive/2013/01/04/2844624.html

本文链接


    
最新技术文章:
▪C#通过IComparable实现ListT.sort()排序
▪C#实现对Json字符串处理实例
▪Winform实现抓取web页面内容的方法
▪Winform实现将网页生成图片的方法
▪C#控制台程序中处理2个关闭事件的代码实例
▪WinForm实现同时让两个窗体有激活效果的特效...
▪WinForm实现拦截窗体上各个部位的点击特效实...
▪用C#的params关键字实现方法形参个数可变示例
▪C#判断某程序是否运行的方法
▪C#验证码识别基础方法实例分析
▪C#通过WIN32 API实现嵌入程序窗体
▪C#实现获取鼠标句柄的方法
▪C#事件处理和委托event delegate实例简述
▪C#获取程序文件相关信息的方法
▪C#中的除法运算符与VB.NET中的除法运算符
▪ASP.NET MVC 5使用X.PagedList.Mvc进行分页教程(PagedLi...
▪Base64编码解码原理及C#编程实例
▪C#实现的优酷真实视频地址解析功能(2014新算...
▪C#和SQL实现的字符串相似度计算代码分享
▪C#使用Word中的内置对话框实例
▪C#反射之基础应用实例总结
▪C#生成单页静态页简单实例
▪C#实现SMTP邮件发送程序实例
▪C#实现随鼠标移动窗体实例
▪C#使用GDI+创建缩略图实例
▪C#实现通过模板自动创建Word文档的方法
▪C#中Response.Write常见问题汇总
▪C#中多态、重载、重写区别分析
▪WinFrom中label背景透明的实现方法
▪C#中out保留字用法实例分析
 


站内导航:


特别声明:169IT网站部分信息来自互联网,如果侵犯您的权利,请及时告知,本站将立即删除!

©2012-2021,,E-mail:www_#163.com(请将#改为@)

浙ICP备11055608号-3