Knowing whether the user is pressing the Shift key

How can I tell whether the Shift key is currently pressed?
I don't need to know when it's pressed. Instead, at an arbitrary point, i want to know whether the Shift key is pressed.
Thanks,
Eli

Try the following code:
import java.awt.AWTEvent;
import java.awt.BorderLayout;
import java.awt.Toolkit;
import java.awt.event.AWTEventListener;
import java.awt.event.ActionEvent;
import java.awt.event.KeyEvent;
import javax.swing.AbstractAction;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.SwingUtilities;
public class ShiftTest implements AWTEventListener {
    public static void main(String[] args) {
     SwingUtilities.invokeLater(new Runnable() {
         @Override
         public void run() {
          new ShiftTest().createGUI();
    private boolean shiftPressed = false;
    public ShiftTest() {
     Toolkit.getDefaultToolkit().addAWTEventListener(this,
          AWTEvent.KEY_EVENT_MASK);
    @Override
    public void eventDispatched(AWTEvent event) {
     if (event.getID() == KeyEvent.KEY_PRESSED) {
         if (KeyEvent.VK_SHIFT == ((KeyEvent) event).getKeyCode()) {
          shiftPressed = true;
     } else if (event.getID() == KeyEvent.KEY_RELEASED) {
         if (KeyEvent.VK_SHIFT == ((KeyEvent) event).getKeyCode()) {
          shiftPressed = false;
    public boolean isShiftPressed() {
     return shiftPressed;
    private void createGUI() {
     JFrame frame = new JFrame();
     frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
     final JLabel label = new JLabel("Message area", JLabel.CENTER);
     frame.add(label, BorderLayout.PAGE_END);
     frame.add(new JButton(new AbstractAction("Test shift pressed") {
         private static final long serialVersionUID = 1L;
         @Override
         public void actionPerformed(ActionEvent e) {
          label.setText("Shift " + isShiftPressed());
     }), BorderLayout.CENTER);
     frame.pack();
     frame.setLocationRelativeTo(null);
     frame.setVisible(true);
}Piet

Similar Messages

  • Opening an application while pressing the shift key

    Recently, Microsoft Word 2011 failed to open and showed the message, "Microsoft Word has encountered a problem and needs to close." I followed troubleshooting instructions on the Microsoft website. Nothing cured the problem, but creating a new user account did enable Word 2011 to open normally. That seemed to imply that "a corrupt user account" was causing the problem. I could not find any instructions about how to repair that, but at some point I came across the suggestion to "hold the shift key down and click on the Word icon in the dock." I did this and Word opened normally in my account. After this, Word opened normally without holding down the shift key. Apparently this fixed the problem.
    My question is, what does pressing the shift key do while you open an application? What's different? Why did it work? What's special about the shift key in this situation?
    Thanks.

    It may be something specific to Word/Office. Individual applications may accept different launch arguments passed to them via key combinations, such as holding the Option key when launching iTunes to invoke the option for choosing the library to use.

  • The pressing the Shift key to make a capital letter kicks me out of gmail or reloads the current web page

    I'm suddenly getting some strange behavior on my Windows 7 PC. (I can hear all you Linux users formulating witty retorts...don't do it! :-). When I'm composing an email in Gmail and press the Shift key to get caps, it kicks me out of the composition page. And nothing is saved in drafts either. Internet Explorer doesn't have this issue. The Shift key works normally. Also, If I try to paste using Ctrl+V it make the webpage text shrink. I was trying to log this issue on the computer with the problem but I couldn't login because of the caps and the paste issue.
    I just discovered another quirk: If I press the Ctrl key without the +V it still shrinks the text.

    Hi Matt,
    Thanks for the suggestion, but there's no option to uninstall a driver. It's a MS Ergonomic 4000 keyboard and it just shows up as an HID compliant device. I tried uninstalling the Microsoft Mouse & Keyboard Control Center, but that didn't help either.
    I've also pressed the keys numerous times (at one point it asked me if I wanted to enable 'Sticky Keys' which I didn't). Rebooted too. Even deleted the user profile, removed the PC from the domain, rejoined it to the domain, logged in as the user, and restored a previously backed up Transfer Wizard profile. And I checked while logged on as the local Admin and got the same weirdness.

  • How to know whether the Content Type at Library level is Inheriting Parent Content type or not Using Powershell?

    Hi,
    How to know whether the Content Type at Library level is Inheriting Parent Content type or not using Powershell?
    Is there any property for that? Or Do I need to compare the Content type Id's at Site collection level and Library level?
    Any help would be greatly appreciated.
    Thank you,
    AA.

    Hi Ashok,
    For a content type, there is an attribute called Inherits, the value of this attribute determines whether the content type inherits fields from its parent content type when it is created.
    If Inherits is TRUE, the child content type inherits all fields that are in the parent, including fields that users have added.
    If Inherits is FALSE or absent and the parent content type is a built-in type, the child content type inherits only the fields that were in the parent content type when SharePoint Foundation was
    installed. The child content type does not have any fields that users have added to the parent content type.
    More information, please refer to the link:
    https://msdn.microsoft.com/en-us/library/office/aa544268.aspx?f=255&MSPPError=-2147217396
    Best Regards,
    Wendy
    TechNet Community Support
    Please remember to mark the replies as answers if they help, and unmark the answers if they provide no help. If you have feedback for TechNet Support, contact
    [email protected]

  • Thinkpad Yoga 14: How to know whether the model had separate trackpad buttons or not

    So Lenovo has released the 2015 version of the Thinkpad Yoga 14. In the online manual it says that some models do and others don't have separate trackpad buttons. How do you know whether the specific models offers do or don't?
    The images in Lenovo's online store show the Thinkpad Yoga 14 without the separate buttons...

    1. Delete all applications you got from the Mac App Store. Also delete any pirated copies of App Store products that you may have installed.
    2. Rebuild the Spotlight index as follows:
    From the menu bar, select
     ▹ System Preferences ▹ Spotlight ▹ Privacy
    The list of items excluded from Spotlight indexing is shown (it may be empty.) Click the plus (“+”) icon to add an item to the list. Select your volume (under DEVICES) and add it to the list. Then remove it from the list by selecting it and clicking the minus (“-“) icon.
    Spotlight will rebuild the index. If you try to do a Spotlight search now from the magnifying-glass icon in the top right corner of the display, a pulsing dot will appear in the icon. When the dot disappears, the indexing is complete.
    3. Check that the Apple ID associated with your account in the Users & Groups preference pane is correct.
    4. Reinstall the applications you deleted by downloading them from the App Store.

  • How to create constrained or unconstrained Kerberos and know whether the back end is constrained or unconstrained Kerberos?

    Hello Community
        I am considering Kerberos Authenication but there seems to be
    2 kinds of Kerberos: constrained and unconstrained.
        Since when creating Kerberos you are only offered things like "Negotiate\Kerberos"
    Or "Negotiate" or "Setspn" the question is how do you create a constrained
    or unconstrained Kerberos and since the back end has to match how do you
    do you know whether the back end uses constrained or unconstrained Kerberos?
        Thank you
        Shabeaut

    Kerb is used for one of several scenarios:
    - connecting SP to SQL databases, which provides assurances around the connection between the SP service accounts and the SQL service accounts
    - connecting SP to external systems (such as SQL databases, which may be used by BCS, Excel, PerformancePoint, PowerPivot, etc).
    Constrained Delegation is not necessary for SP to use Kerb when connecting to SQL. it IS necessary for SP to talk to external systems (since Constrained Delegation is also known as "Kerberos with protocol transition", since it's
    transitioning a Claims based auth token to a kerberos based auth token).
    The difference is a setting in AD's Delegation tab, for the service account that will be collecting the users' login (presumably the webapp), and for the service account that will be performing the double-hop (presumably the service apps)... in addition
    to the kerb setting, you also need to specify EXACTLY which endpoints can be reached using the Kerb + CD... unconstrained delegation (the default) allows the Kerb token to be passed anywhere... constrained delegation only allows the Kerb token to be used
    by the places you specify (in the delegation tab)... such as the SQL server that the PerformancePoint scorecards will be querying.
    Links:
    - Microsoft's Kerberos guide : http://www.microsoft.com/en-us/download/details.aspx?id=23176
    - more links : http://www.sbrickey.com/Tech/Blog/Post/SharePoint_Troubleshooting_Kerberos_and_External_Data_from_Excel_Services
    - some health analyzers to find problems and recommend solutions : http://sdssharepointlibrary.codeplex.com/releases/view/92022
    Scott Brickey
    MCTS, MCPD, MCITP
    www.sbrickey.com
    Strategic Data Systems - for all your SharePoint needs

  • I wish to know whether the new NVidia Quadro K2200 graphic card is compatible with the Mercury Playback Engine.  Thanks

    Hi.  I wish to know whether the new NVidia Quadro K2200 and K4200 are compatible with the Mercury Playback Engine in Adobe Premiere Pro CS6.  My old graphic card NVidia Quadro FX580 is not listed and not effective apparently because Mercury Playback Engine is effective as from 1Gb RAM. I use a HP workstation and AVCHD (AVCCAM) and DSLR full HD.  Thanks.
    Message was edited by: Brittany Mauriss
    Deleted private user information (email address)

    It is compatible, but why anyone would want such a weak and slow card at a premium price is beyond me. See Tweakers Page - What video card to use? and GeForce GTX980 vs Quadro k4200 (2200) #2.

  • Any way to know whether the column of matrix is active at run-time?

    Hi all,
    I have posted similar question earlier but it was for setting the column prefrences . In a system form, I am having some user defined columns to which I am copying some data. If they are not active, and if I try to do
    Matrix.Columns.Item("U_STNLineno").Editable = True,
    It gives me 'form item is not editable' error.
    I can fetch the active status from CPRF table, but it  updates the status only after SAP B1 is closed.
    If atleast, I know, at run time, tht the column is not active, I can prompt user a warning to make it active from form settings.
    But, How do I know whether the column is active or not?
    any clue?
    Thanks in advance..
    Binita

    Maybe is better solution, but I`m doing it that I`m trying in system objects to do
    Matrix.Columns.Item("U_STNLineno").Editable = True
    between try catch statement and if is there any error which contains "editable" sentence, I know that it is`nt allowed.
    it should be done as
    on error resume next
    Matrix.Columns.Item("U_STNLineno").Editable = True
    if Err.Description <> "" then
    -- cannot set
    end if
    on error goto 0
    Petr

  • [help]how to know whether the given column exists in the table or not????

    Hi all, can anyone tell me how to write a C# code help me to know whether the given field exists.
    If it doesnt exists then i want to alter the table to include this column also
    I am able to write the code for alter table but i m not sure how do i check for its existence/nonexistence
    My Altering code
    {color:#800000}cmd.CommandText = "alter table " + row.ToString() + " add(" + sQuality + " varchar2(50), " +
    sTimeStamp + " varchar2(50), " +
    sValue + " varchar2(50))";
    cmd.CommandType = CommandType.Text;
    cmd.ExecuteReader();
    {color}

    Just iterate the datatable after completion and check for your column.
            public static DataTable MaterializeTableStructure(string _connectionString, string _tableName)
                DataSet ds = null;
                using (OracleConnection _oraconn = new OracleConnection(_connectionString))
                    try
                        _oraconn.Open();
                        string sql = "SELECT COLUMN_NAME, DATA_TYPE, NULLABLE, DATA_LENGTH, DATA_PRECISION, DATA_SCALE FROM user_tab_columns where table_name='" + _tableName + "'";
                        using (OracleCommand cmd = new OracleCommand(sql, _oraconn))
                            cmd.CommandType = CommandType.Text;
                            using (OracleDataAdapter da = new OracleDataAdapter(cmd))
                                ds = new DataSet("MaterializeTableStructure");
                                da.Fill(ds);
                    catch (OracleException _oraEx)
                        throw (_oraEx); // Actually rethrow
                    catch (System.Exception _sysEx)
                        throw (_sysEx); // Actually rethrow
                    finally
                        if (_oraconn.State == ConnectionState.Broken || _oraconn.State == ConnectionState.Open)
                            _oraconn.Close();
                if (ds != null)
                    return ds.Tables[0];
                else
                    return null;
            }r,
    dennis

  • How to know whether the javascript is disabled or not while loading the jsp

    Hi,
    My query is like how to know whether the javascript is disabled or not while loading the Application main JSP in Mozilla browser.
    I want some Java code or JavaScript code.

    To the point, just let JS fire a specific HTTP request inside the same session.
    This can be done in several ways. 1) Create a hidden <img> element and set the `src` attribute so that it will request a (fake) image from the server. The server just have to intercept on this specific request. 2) Fire an ajaxical request and let the server intercept on it. You can use a Filter for this which sets a token in the session scope to inform that the client has JS enabled.

  • How to know whether the current database is using a password file or not?

    How to know whether the current database is using a password file or not?

    The remote_password_file is the parameter that determines if you can use or not a password file. The values this parameter can have are NONE, SHARED, EXCLUSIVE. It is pretty obvious, if it is set to either SHARED or EXCLUSIVE the oracle instance has enabled the access through a password file for the SYSDBA and SYSOPER roles.
    ~ Madrid

  • How to know whether the installed Oracle is 32 bits(or 64 bits)?

    I have installed Oracle 8.1.6 on HP-UX 11(64 bits OS ), But I dont know whether the oracle is 64 bits.
    How can I get to know it?
    Thanks!
    null

    Hi, This is late though, but to let you know that Oracle 8.1.6 is 64-bits
    Duronke
    <BLOCKQUOTE><font size="1" face="Verdana, Arial, Helvetica">quote:</font><HR>Originally posted by zhihui zu ([email protected]):
    I have installed Oracle 8.1.6 on HP-UX 11(64 bits OS ), But I dont know whether the oracle is 64 bits.
    How can I get to know it?
    Thanks!
    <HR></BLOCKQUOTE>
    null

  • How to know whether the database is using SPFILE or PFILE

    How can i know whether the database is using SPFILE or PFILE.
    There are both initSID.ora and spfileSID.ora in default location.
    The registry entry for ORA_SID_PFILE is C:\oracle\ora90\database\initSID.ora
    Also, if it is using SPFILE than how can i modify the non dynamic parameters when the database is in the close state.
    Manu

    If you do not specify a path of a pfile , when you actually startup a database , then it will be use your pfile , if you specify a path explicitly fot a pfile , then it'll use your pfile.
    Also, if it is using SPFILE than how can i modify the non dynamic parameters when the database is in the close state.sql > create spfile from pfile ;
    the spfile will syncronise with pfile .
    Hare krishna
    Alok

  • How to know whether the changes are implemented by sap or not(not manually)

    Hi,
    On 4.7 version in some standard objects(SAP Objects) some changes are done by custom by using modification assistance.
    On ecc 6.0 version I need to know whether the same changes are done by custom or sap? ( not manually)
    Let me know is there any process to know the changes done by sap or custom on ecc 6.0.
    Thanks,
    Radhika

    Hi ,
    u can check  for entries  in table ADIRACCESS.
    Regards
    prabhu

  • How do I know whether the USB port in my macbook air is 2.0 or 3.0?

    How do I know whether the USB port in my macbook air is 2.0 or 3.0? I really want to use a usb flash drive that has faster read/write speed but I don't kow if it would be supported by my macbook air - I purchased the macbook air from the apple store on autumn 2011, 1.7Ghz Intel Core i5

    Eddy ~ The free Mactracker app shows USB info and much more:

Maybe you are looking for

  • Error when we try to load the datasource

    Hi all, We create a EJB project with oracle 9i database, when we execute the application and, for example, from our session bean we try to call a findByPrimaryKey() method over our entity bean, the container load the datasource (the database is confi

  • Final Cut loading and running extremely slow...

    Hi, I posted about this a few days ago but in my usual panic (work to do!) I didn't make it clear, basically, here's the problem... I recently had problems with FCP and generally all apps on my machine, when they loaded there was a slight pause when

  • How to Determine the first day of the current Fiscal Year

    I am a SQL Server developer who is trying to to learn Oracle SQL. I am trying to write a query that will 1) determine the month number and if the number is 10, 11, or 12, will return '01-Oct-' of the current Calendar year. If the month number is betw

  • Ragarding ALV Report output  running  in background

    Hi All,             When i running report in background , the output is not formatted. i.e. output is not coming in single row for a particular row in a report,it is down to second row. as result when i spool this output to excel (spread sheet) ,the

  • I can not import raw photos into my i photo 09 using nikon D5100 ?

    I an unable to import raw files from nikon D5100 camera into i photo 09 help please