Click here to Skip to main content
15,902,937 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I want to open the form on key press of Alt+F.
What to do for this. If any one have any idea.
Thanks in advance.
Posted
Comments
_Amy 10-Sep-12 7:06am    
What have you tried yet? The question should start from "This is what I tried" not from "This is what I want". Since you are a regular user of CP, you should not do these kinds of mistake.

Have a look on this search results[^]
 
Share this answer
 
Hi,

you need to subscribe to the "KeyDown" event. Here is an example:
C#
private void Form1_KeyDown(object sender, KeyEventArgs e)
{
  if (e.KeyCode == Keys.F && e.Modifiers == Keys.Alt)
  {
    //Show the form
  }
}
 
Share this answer
 
for windows Application:
C#
private void Form1_KeyDown(object sender, KeyEventArgs e)
       {
           if (e.Alt & e.KeyCode.ToString() == "F")
           {
               Form2 op = new Form2();
               op.Show();
           }
       }

for Web Application:
ASP.NET
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default7.aspx.cs"
 Inherits="Default7" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
   <title>Untitled Page</title>
  <script type="text/javascript">
  document.attachEvent('onkeyup', KeysShortcut);


// Now we need to implement the KeysShortcut
function KeysShortcut ()

{

    if (event.keyCode == 17) // 17 keycode is for Left control key

    {
      document.getElementById('<%= button1.ClientID %>').click();

    }

}
  </script>
</head>
<body>
   <form id="form1" runat="server">
   <div>
   <asp:ScriptManager ID="a" runat="server"></asp:ScriptManager>
   </div>
  <div id="target" style="background-color: gray">This is a simple div</div>
    <asp:Button ID="button1" runat="server" onclick="Button1_Click" />
   </form>
</body>


</html>

C#
protected void Button1_Click(object sender, EventArgs e)
   {
       Response.Redirect("About.aspx", false);
   }
 
Share this answer
 
v3
check for keyboardhook exaples..
 
Share this answer
 
use this code
C#
if (e.KeyCode == Keys.F && e.Modifiers == Keys.Alt)
            {
               //do something
            }
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900