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

using System;
using System.Collections.Generic;
using System.ComponentModel;
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.181288 second(s), 8 queries.
Copyright©2004-2018, BCCN.NET, All Rights Reserved