473,574 Members | 2,636 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Application Starting - detecting Shift Key pressed

Hello,

I would like to cancel an action if the user holds the shift key while
the application is starting-up.
Would you know what is the best way to do so please?
Thanks,
Michael

--
Michael
----
http://michael.moreno.free.fr/
http://port.cogolin.free.fr/

Jan 23 '06 #1
5 13843
I'm assuming the main question is about the [Shift] key (not cancelling an
action):

Just test the Control modifiers:

if ((System.Window s.Forms.Control .ModifierKeys & Keys.Shift) == Keys.Shift)
{
System.Diagnost ics.Debug.Write Line("Shift down");
}

This appears to work even for console applications (if you adda a
reference), which is quite nice...

Marc
Jan 23 '06 #2
"Michael Moreno" <mi************ *********@free. fr> wrote in
news:mn******** *************** @free.fr:
I would like to cancel an action if the user holds the shift key while
the application is starting-up.
Would you know what is the best way to do so please?


If you do it from within the Form class, you can use the 'ModifierKeys'.
If you want to do it from Main(...) or anywhere else outside of the Form,
then you can use PInvoke:

[DllImport("user 32.dll")]
static extern short GetKeyState(Vir tualKeyStates nVirtKey);

int ks = GetKeyState(Vir tualKeyStates.V K_SHIFT);
if ((ks & 0x80) != 0)
{
// SHIFT KEY is pressed
}

BTW the VirtualKeyState s is an enum defined at pinvoke.net:

http://pinvoke.net/default.aspx/user32.GetKeyState

But if you wanted you could just set the PInvoke signature to use an int
and pass 0x10.

-mdb
Jan 23 '06 #3
See my previous post - you don't actually need the PInvoke step, regardless
of whether you are working with a Form subclass.

Marc
Jan 23 '06 #4
Great!!!
Thank you very much

--
Michael
----
http://michael.moreno.free.fr/
http://port.cogolin.free.fr/

Jan 23 '06 #5
"Marc Gravell" <mg******@rm.co m> wrote in
news:eR******** *****@TK2MSFTNG P15.phx.gbl:
See my previous post - you don't actually need the PInvoke step,
regardless of whether you are working with a Form subclass.


Yeah I saw that... that's a good point - thanks for the tip.

-mdb
Jan 23 '06 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
2639
by: Kiteman - Canada | last post by:
Is there an event triggered when a form is dragged by its titlebar? I have two forms on screen - the main form is draggable and I need the secondary form to automatically reposition itself adjacent to the main form if the main form is relocated. Tom
5
2357
by: Alex Stevens | last post by:
Hi All, I'm writing a launcher program which checks for updates and copies them down to the client. However, I would like the user to be able to modify the settings for the launcher. As this runs automatically, I would like it to be configurable by the user holding down the shift key when double-clicking my exe, to bypass the usual update...
1
1592
by: Kejpa | last post by:
Hi! How can I detect if Shift (and/or Ctrl and/or Alt) is pressed in the click event of a ToolBar button? TIA /Kejpa
5
8932
by: Boni | last post by:
Dear all, How do I get information if Shift is pressed in a mouse wheel handler. Thanks, Boni Sub MouseWheel(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) 'mouse whill handler If SHIFT is pressed and e.delta..... End Sub
2
4555
by: sytemper | last post by:
I write a keydown KeyDown event to catch if tab is press or tab+shift is press.And i already override the IsInputKey method. But noe i only can get the tab but no shift+tab. When shift+tab is press, i only get KeyCode=ShiftKey,and KeyData=65552, but nothing to show that tab is also pressed. What should i do now?
1
2338
by: Frank Rizzo | last post by:
I'd like to detect a condition when a user presses a predefined keyboard combination. For instance, left shift + right control + 5 on the number pad. I've tried the KeyDown event on the form. But I can't determine which shift (or control) key was pressed (right or left). I've tried e.KeyCode, e.KeyData, e.Modifiers. Am I missing...
4
4871
by: Johnny J. | last post by:
How do you check if the Control, Shift or Alt key is pressed at any given time (not necessarily in a keyevent)? Cheers, Johnny J.
4
7050
by: hui11 | last post by:
Hi, According to the doc at mozilla, http://developer.mozilla.org/en/docs/DOM:event.charCode, the charCode takes shift into consideration when pressed. I found that to be true for other cases except when Alt+Shift is pressed. For example, the charCode alt+shift+a does not reflect a capitalized a, 'A', or alt+shift+1 does not reflect '!',...
2
4790
by: bobh | last post by:
Hi All, In AccessXP I have a form, it has a form header, detail and footer sections. When done entering text in a txtbox(bxReqst) in the footer the user wants to press the Tab key and have the focus move to a control called bxQues in the Detail section. From the control in the footer how do I detect when a Tab key is pressed and set the...
0
7814
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
8067
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8107
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
1
5631
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5307
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3756
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2252
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1352
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1071
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.