{"id":2144,"date":"2026-06-24T16:18:40","date_gmt":"2026-06-24T08:18:40","guid":{"rendered":"https:\/\/xlwings.net\/blog\/?p=2144"},"modified":"2026-03-28T08:03:09","modified_gmt":"2026-03-28T08:03:09","slug":"how-to-use-applicationmouseavailable-in-the-xlwings-api-way","status":"publish","type":"post","link":"https:\/\/xlwings.net\/blog\/how-to-use-applicationmouseavailable-in-the-xlwings-api-way\/","title":{"rendered":"How to use Application.MouseAvailable in the xlwings API way"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">The Application.MouseAvailable property in Excel&#8217;s object model is a read-only property that returns a Boolean value indicating whether a mouse is available on the system. This can be useful in scenarios where your automation script needs to adapt its behavior based on the presence of a mouse, such as avoiding mouse-dependent operations on systems without one, or providing alternative user interface cues. In xlwings, you access this property through the Application object, which is typically represented by the <code>app<\/code> object when you connect to an Excel instance.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The syntax in xlwings for accessing the MouseAvailable property is straightforward, as it maps directly to the underlying Excel object model. You can retrieve its value using the following format:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>app.mouse_available<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Here, <code>app<\/code> is an instance of the xlwings App class, which represents the Excel application. The property does not take any parameters, and it returns <code>True<\/code> if a mouse is available, or <code>False<\/code> otherwise. This is a property, so you read it like an attribute; you cannot set or modify its value.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">For example, consider a situation where you are developing a macro or an automated report that includes interactive elements like shapes or buttons that require mouse clicks for user interaction. Before executing such mouse-dependent steps, you might want to check for mouse availability to ensure the script runs smoothly or to log an appropriate message. Below is a practical xlwings code example:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>import xlwings as xw\n\n# Connect to the active Excel instance or start a new one\napp = xw.apps.active\n\n# Check if a mouse is available\nif app.mouse_available:\n    print(\"Mouse is available. Proceeding with mouse-dependent operations.\")\n    # For instance, you could activate a worksheet and select a range\n    wb = app.books.active\n    ws = wb.sheets&#91;0]\n    ws.range(\"A1\").select() # This selection might rely on mouse interaction in some contexts\nelse:\n    print(\"No mouse detected. Skipping mouse-dependent steps or using keyboard alternatives.\")\n    # Implement fallback logic, such as using keyboard shortcuts or focusing on data processing only<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n","protected":false},"excerpt":{"rendered":"<p>The Application.MouseAvailable property in Excel&apos;s object model is a read-only property that returns&#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[25],"tags":[],"class_list":["post-2144","post","type-post","status-publish","format-standard","hentry","category-xlwings-api-reference"],"_links":{"self":[{"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/posts\/2144","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/comments?post=2144"}],"version-history":[{"count":1,"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/posts\/2144\/revisions"}],"predecessor-version":[{"id":3279,"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/posts\/2144\/revisions\/3279"}],"wp:attachment":[{"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/media?parent=2144"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/categories?post=2144"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/tags?post=2144"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}