| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1493 人关注过本帖
标题:求教热键设置涉及小键盘的数字键问题
只看楼主 加入收藏
wedf888
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2015-11-5
收藏
 问题点数:0 回复次数:0 
求教热键设置涉及小键盘的数字键问题
小白一枚,后面跟我的代码,如何让按下含有Shift功能键时 再按小键盘数字键时过滤掉,不输入内容!
或者有完整的由用户自定义全局热键代码也可以。
代码写的不好,只会if结构,见笑了!

using System;
using System.Collections.Generic;
using
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;

namespace HotKey
{
    public partial class Form1 : Form
    {
        int modifiers;
        Keys key;
        public Form1()
        {
            InitializeComponent();
        }
        public static string GetString(Keys key)
        {
            //if (key == Keys.Delete || key == Keys.Insert || key == Keys.End || key == Keys.Down || key == Keys.PageDown || key == Keys.Left || key == Keys.Clear || key == Keys.Right || key == Keys.Home || key == Keys.Up || key == Keys.PageUp)
            //{
            //    return "";
            //}
            if (key == Keys.None || key == Keys.Alt || key == Keys.Menu || key == Keys.Control || key == Keys.ControlKey || key == Keys.Shift || key == Keys.ShiftKey)
            {
                return "";
            }
            if (key == Keys.Oemtilde)
            {
                return "~";
            }
            string str = key.ToString();
            return str;
        }
        public int GetInt32(Keys key)
        {
            if (key == Keys.Alt || key == Keys.Menu)
            {
                return 1;
            }
            else if (key == Keys.Control)
            {
                return 2;
            }
            else if (key == (Keys.Control | Keys.Alt))
            {
                return 3;
            }
            else if (key == Keys.Shift)
            {
                return 4;
            }
            else if (key == (Keys.Shift | Keys.Alt))
            {
                return 5;
            }
            else if (key == (Keys.Shift | Keys.Control))
            {
                return 6;
            }
            else if (key == (Keys.Shift | Keys.Control | Keys.Alt))
            {
                return 7;
            }
            return 0;
        }
        private void textBox1_KeyDown(object sender, KeyEventArgs e)
        {
            int i = textBox1.TabIndex;
            string str;
            modifiers = GetInt32(e.Modifiers);
            if (modifiers == 0) { textBox1.Text = ""; } else { str = e.Modifiers.ToString(); str = str.ToString().Replace(",", " +"); textBox1.Text = str + " + "; }

            str = GetString(e.KeyCode);
            if (str == "")
            {
                key = Keys.None;
            }
            else
            {
                key = e.KeyCode;
                textBox1.Text += str;
            }
        }
    }
}
搜索更多相关主题的帖子: public 功能键 键盘 如何 用户 
2015-11-05 02:04
快速回复:求教热键设置涉及小键盘的数字键问题
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.044159 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved