{"id":6277,"date":"2021-08-09T07:47:33","date_gmt":"2021-08-09T07:47:33","guid":{"rendered":"https:\/\/www.greytrix.com\/blogs\/salesforce\/?p=6277"},"modified":"2021-08-09T07:47:35","modified_gmt":"2021-08-09T07:47:35","slug":"key-event-listener-in-lwc-lightning-web-component","status":"publish","type":"post","link":"https:\/\/www.greytrix.com\/blogs\/salesforce\/2021\/08\/09\/key-event-listener-in-lwc-lightning-web-component\/","title":{"rendered":"Key Event\/Listener in LWC (Lightning Web Component)"},"content":{"rendered":"\n<p>Lot of times user needs to enter data quickly. \u00a0In this case we would like to share with you how we have built a custom screen to enter Order Lines data quickly. But we had a unique requirement is that wherein when the user enters <strong>ENTER <\/strong>keyword, control needs to go to next line on same field. <\/p>\n\n\n\n<p>We built this screen in Lightning Web Component (LWC) but there is no direct event to catch keypress for lightning-input. As a workaround we have used below code to listen <strong>ENTER <\/strong>key.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>span onkeypress={key_event}>\r\n    &lt;lightning-input id=\"Input_Id\" label=\"Enter\" \r\n                         type=\"text\" onchange={Test_Event}>\r\n    &lt;\/lightning-input>\r\n&lt;\/span>\r<\/code><\/pre>\n\n\n\n<p>Here we have added HTML &lt;span> element across lightning-input\u00a0to catch the keypress event. Since span is standard HTML element and have inbuilt keypress event so we have utilized same in our code. <\/p>\n\n\n\n<p>Below code is for JS file<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Key_event (component, event, helper) {\r\n        if (component.which == 13) {\r\n            alert (Perform some action ');\r\n       }\r\n   }<\/code><\/pre>\n\n\n\n<p>Here we have used <strong>component.which <\/strong>property to identify the key code. Likewise, you can use <strong>component.which <\/strong>property to identify the key codes.<\/p>\n\n\n\n<p><em><strong>You can find all key code at the web site <a href=\"http:\/\/gcctech.org\/csc\/javascript\/javascript_keycodes.htm\" target=\"_blank\" rel=\"noopener\">http:\/\/gcctech.org\/csc\/javascript\/javascript_keycodes.htm<\/a><\/strong><\/em><\/p>\n\n\n\n<p>Using the details mentioned in the blog we hope you are able to make use of the keypress event for capturing the details. <\/p>\n\n\n\n<p>We hope you may find this blog resourceful and helpful. If you still have concerns and need more help, please contact us at\u00a0<a href=\"mailto:salesforce@greytrix.com\">salesforce@greytrix.com<\/a>. <\/p>\n\n\n\n<p style=\"text-align: justify\"><b>About Us<\/b><\/br>\n<p><a href=\"https:\/\/www.greytrix.com\/\">Greytrix<\/a> \u2013 a globally recognized and one of the oldest Sage Development Partner and a Salesforce Product development partner offers a wide variety of integration products and services to the end users as well as to the Partners and Sage PSG across the globe. We offer Consultation, Configuration, Training and support services in out-of-the-box functionality as well as customizations to incorporate custom business rules and functionalities that require apex code incorporation into the Salesforce platform.<br><br> Greytrix has some unique solutions for Cloud CRM such as <a href=\"\">Salesforce Sage integration<\/a> for <a href=\"https:\/\/www.greytrix.com\/sage-x3-erp\/integration\/\">Sage X3<\/a>, <a href=\"https:\/\/www.greytrix.com\/salesforce-cloud-services\/sage-100-integration\/\">Sage 100<\/a> and <a href=\"https:\/\/www.greytrix.com\/salesforce-cloud-services\/sage-300-integration\/\">Sage 300 (Sage Accpac)<\/a>. We also offer best-in-class Cloud CRM <a href=\"https:\/\/www.greytrix.com\/salesforce-cloud-services\/crm-development\/\">Salesforce customization and development services<\/a> along with services such as Salesforce <a href=\"https:\/\/www.greytrix.com\/salesforce-cloud-services\/data-migration-support\/\">Data Migration<\/a>, <a href=\"https:\/\/www.greytrix.com\/salesforce-cloud-services\/crm-development\/\">Integrated App development<\/a>, Custom App development and Technical Support business partners and end users. Salesforce Cloud CRM integration offered by Greytrix works with Lightning web components and supports standard opportunity workflow. Greytrix GUMU&#x2122; integration for Sage ERP \u2013 Salesforce is a 5-star rated app listed on <a href=\"https:\/\/appexchange.salesforce.com\/appxListingDetail?listingId=a0N30000000psM5EAI\" target=\"_blank\" rel=\"noopener\">Salesforce AppExchange<\/a>.<br> The GUMU&#x2122; Cloud framework by Greytrix forms the backbone of cloud integrations that are managed in real-time for processing and execution of application programs at the click of a button.<br><br> For more information on our Salesforce products and services, contact us at <a href=\"mailto:salesforce@greytrix.com\">salesforce@greytrix.com<\/a>. We will be glad to assist you.<\/p>\n\n\n\n<p><strong>Related Posts<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\" id=\"block-95f1dc03-6e6e-4324-a224-6cb667f07601\"><li><a rel=\"noreferrer noopener\" href=\"https:\/\/www.greytrix.com\/blogs\/salesforce\/2021\/07\/21\/how-to-remove-apex-code-from-production-environment\/\" data-type=\"URL\" data-id=\"https:\/\/www.greytrix.com\/blogs\/salesforce\/2021\/07\/21\/how-to-remove-apex-code-from-production-environment\/\" target=\"_blank\">How to remove Apex Code from Production Environment<\/a><\/li><li><a rel=\"noreferrer noopener\" href=\"https:\/\/www.greytrix.com\/blogs\/salesforce\/2021\/05\/29\/how-to-add-utility-bar-in-a-salesforce-lightning-application\/\" target=\"_blank\">Adding Utility bar in a Salesforce lightning application<\/a><\/li><li><a rel=\"noreferrer noopener\" href=\"https:\/\/www.greytrix.com\/blogs\/salesforce\/2021\/06\/28\/how-to-display-toasts-or-notices-using-lightning-notificationlibrary\/\" target=\"_blank\">How to Display Toasts or Notices using Lightning : NotificationLibrary<\/a><\/li><li><a rel=\"noreferrer noopener\" href=\"https:\/\/www.greytrix.com\/blogs\/salesforce\/2021\/03\/24\/add-delete-row-dynamically-in-salesforce-lightning\/\" target=\"_blank\">Add Delete Row Dynamically In Salesforce Lightning<\/a><\/li><li><a rel=\"noreferrer noopener\" href=\"https:\/\/www.greytrix.com\/blogs\/salesforce\/2021\/06\/15\/how-to-add-or-remove-css-style-from-the-component-element-during-runtime-or-dynamically\/\" target=\"_blank\">How to Add or Remove CSS style from the component\/element during runtime or dynamically<\/a><\/li><li><a rel=\"noreferrer noopener\" href=\"https:\/\/www.greytrix.com\/blogs\/salesforce\/2021\/04\/12\/how-to-notify-user-about-unsaved-changes-on-the-ui-using-lightning-component\/\" target=\"_blank\">How to Notify User about Unsaved Changes on the UI using Lightning Component<\/a><\/li><li><a rel=\"noreferrer noopener\" href=\"https:\/\/www.greytrix.com\/blogs\/salesforce\/2021\/01\/22\/salesforce-how-to-get-row-index-of-lightning-table-rows\/\" target=\"_blank\">Salesforce \u2013 How to get row index of lightning table rows<\/a><\/li><\/ul>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Lot of times user needs to enter data quickly. \u00a0In this case we would like to share with you how we have built a custom screen to enter Order Lines data quickly. But we had a unique requirement is that wherein when the user enters ENTER keyword, control needs to go to next line on\u2026 <span class=\"read-more\"><a href=\"https:\/\/www.greytrix.com\/blogs\/salesforce\/2021\/08\/09\/key-event-listener-in-lwc-lightning-web-component\/\">Read More &raquo;<\/a><\/span><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[1179,206,1055,1069,207,208,1050,1049,1178,367,677,651,1032],"class_list":["post-6277","post","type-post","status-publish","format-standard","hentry","category-salesforce-srv","tag-key-code","tag-lightning","tag-lightning-aura-component","tag-lightning-aura-method","tag-lightning-basics","tag-lightning-component","tag-lightning-web-component","tag-lwc","tag-lwc-key-event","tag-salesforce","tag-salesforce-lightning","tag-salesforce-lightning-component","tag-salesforce-lightning-component-bundle"],"_links":{"self":[{"href":"https:\/\/www.greytrix.com\/blogs\/salesforce\/wp-json\/wp\/v2\/posts\/6277","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.greytrix.com\/blogs\/salesforce\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.greytrix.com\/blogs\/salesforce\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.greytrix.com\/blogs\/salesforce\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.greytrix.com\/blogs\/salesforce\/wp-json\/wp\/v2\/comments?post=6277"}],"version-history":[{"count":2,"href":"https:\/\/www.greytrix.com\/blogs\/salesforce\/wp-json\/wp\/v2\/posts\/6277\/revisions"}],"predecessor-version":[{"id":6279,"href":"https:\/\/www.greytrix.com\/blogs\/salesforce\/wp-json\/wp\/v2\/posts\/6277\/revisions\/6279"}],"wp:attachment":[{"href":"https:\/\/www.greytrix.com\/blogs\/salesforce\/wp-json\/wp\/v2\/media?parent=6277"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.greytrix.com\/blogs\/salesforce\/wp-json\/wp\/v2\/categories?post=6277"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.greytrix.com\/blogs\/salesforce\/wp-json\/wp\/v2\/tags?post=6277"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}