Assign shortcut to a "Saved Function"
-
Wow. Calm down. We are all trying to help you.
You still haven’t answered Alan’s question, or my rephrasing of it. If you want help, answer the question. If you don’t want help, you don’t have to respond.
-
…haven’t directly answered his question: are you willing to have a Ctrl+Shift toggle for the text direction that would (1) require that you install the PythonScript plugin as well as install a script in that plugin, and (2) require that you hold down the Ctrl+Shift for a “long” period of time (my guess is something on the order of 1-2 seconds).
I think I see a way for requirement (2) to go away, and just a short blip of Ctrl+Shift (down and then up again) to actuate the functionality!
-
@PeterJones said in Assign shortcut to a "Saved Function":
Wow. Calm down.
Don’t tell me “Calm Down”!!!
Chill out boy… in front of your machine!!! You are not here in front of my face to tell me that. -
@Alan-Kilborn
Do you mean by pressing Ctrl+Shift (at the same time) twice? -
@Alan-Kilborn
I forgot to say (!) in MS Word and MS NP by pressing the left Shift+Ctrl the text direction goes left and by pressing the right Shift+Ctrl the text direction goes right. -
Do you mean by pressing Ctrl+Shift (at the same time) twice?
No, I was trying to illustrate that you’d press and release Ctrl+Shift to toggle the direction. It would work on the release, so if you press and held Ctrl+Shift, as long as you didn’t add anything to that – for example the
f
key which would immediately invoke Find in Files – when you release Ctrl+Shift, the desired action would occur.I forgot to say (!) in MS Word and MS NP by pressing the left Shift+Ctrl the text direction goes left and by pressing the right Shift+Ctrl the text direction goes right.
This was brought up by Peter before but you didn’t comment on it; I guess you were consumed with how to reply to Peter’s other statements.
So what do you want…do you want it to work like you say notepad.exe and Word do?:
- LShift+LCtrl = LTR
- RShift+RCtrl = RTL
-
@Alan-Kilborn said in Assign shortcut to a "Saved Function":
Do you mean by pressing Ctrl+Shift (at the same time) twice?
No, I was trying to illustrate that you’d press and release Ctrl+Shift to toggle the direction. It would work on the release, so if you press and held Ctrl+Shift, as long as you didn’t add anything to that – for example the
f
key which would immediately invoke Find in Files – when you release Ctrl+Shift, the desired action would occur.I forgot to say (!) in MS Word and MS NP by pressing the left Shift+Ctrl the text direction goes left and by pressing the right Shift+Ctrl the text direction goes right.
This was brought up by Peter before but you didn’t comment on it; I guess you were consumed with how to reply to Peter’s other statements.
So what do you want…do you want it to work like you say notepad.exe and Word do?:
- LShift+LCtrl = LTR
- RShift+RCtrl = RTL
How can I enable this behaviour? Changing TD (Text Direction) by pressing/holding Ctrl+Shift, then releasing them. Is it possible without a plugin or scripting? I know nothing about scripting (I know Python is one of the coding languages).
AFAIK minimal portable version has some problems with plugins. I had 2/3 of them installed on plugin folders, and they had a problem. I wrote to their authors, and as I can remember they said it’s something wrong with the minimal portable version, not their plugin. That was years ago, I even can’t remember what the plugin’s name was.By saying that, I mean I forgot to mention this (RCtrl+RShift -> RTL …) in my second post (that I attached a video for You).
Both of your suggestion is OK! Which one is more simple to imply in NP++? How can I enable them?
-
So I started on a solution for this, but it was developed with the original “spec” in force, and that is that Ctrl+Shift would toggle the current text direction.
I will change the solution so that the left set of keys will set LTR and the right set of keys will set RTL, but it will take me a bit to finish it. Check back later.
BTW, I sort of regret taking this on, given what has transpired in this thread, but I will push on because I think the solution is somewhat interesting, and could be of interest to others.
-
@Alan-Kilborn
What do you mean exactly? Say it directly. Do you mean you regret taking this on because of my replies? Or something else?Despite someone’s words about me in this thread -> …trying to help you!!! I never need any help, never! Need or Help have no room/place in my brain’s dictionary. They are unidentified and unknown to me! I am not familiar with them. If you regret because of MY words! Don’t take it hard, and don’t pressure yourself! Be brave enough to tell it directly! I had no offensive intention to any nationality, person, or language! I just hate coward people which hide behind their machines (PCs, laptops, tablets, smartphones) in their room, and they think they are the brave heart that they are typing a bunch of glyphs on a bunch of pixels! Calm Down! I swear they even know nothing about Calming down! This compound word just had been injected into their brain and blood in their childhood, and they learned just to play it whenever their age number grows! Whenever somebody tells you “Calm Down”, he knows nothing about that he is insisting divert it to you! My response in a millisecond is because I don’t want my “calm down” mode (not mood) to be interrupted even for a millisecond! I am always calm down.
I solve my problems in the real world with real things not with virtual things that I couldn’t touch/smile/see/hear them!This app and all digital things I am using have the role of toys for me, they are not my day-to-day NEEDS. They are just a bunch of 0-1! Nothing more. I wouldn’t die without a bunch of 0-1. Almost all of the day I am walking (not exercising, I don’t do boxing anymore). My job asks me to walk! My job has nothing to do with Windows or Apps! I have no Smart Phone (I hate that), no personal photos/videos/docs on my PC! I am not dependent on digital things. Just FYI. Maybe it helps you to make a better decision! Either don’t do anything or don’t blame anyone. You are doing nothing for ME! There is no “Me” and “I” out there, those are just in YOUR mind and YOUR imagination.
BTW, I assume your finger is not pointing at me (your regret!), and I appreciate your work.
Many thanks for your time and your reply. God bless you and your family! -
Here’s the finished PythonScript2 script. I call the script
ShiftPlusCtrlChangesLtrRtlMode.py
. Further information about obtaining the necessary plugin and setting it up may be found HERE.# -*- coding: utf-8 -*- from __future__ import print_function # references: # https://community.notepad-plus-plus.org/topic/23402/assign-shortcut-to-a-saved-function from Npp import * import ctypes from ctypes import wintypes import platform #------------------------------------------------------------------------------- user32 = ctypes.WinDLL('user32') notepad.hwnd = user32.FindWindowW(u'Notepad++', None) editor1.hwnd = user32.FindWindowExW(notepad.hwnd, None, u'Scintilla', None) editor2.hwnd = user32.FindWindowExW(notepad.hwnd, editor1.hwnd, u'Scintilla', None) LRESULT = wintypes.LPARAM WndProcType = ctypes.WINFUNCTYPE( LRESULT, # return type wintypes.HWND, wintypes.UINT, wintypes.WPARAM, wintypes.LPARAM # arguments ) running_32bit = platform.architecture()[0] == '32bit' SetWindowLong = user32.SetWindowLongW if running_32bit else user32.SetWindowLongPtrW SetWindowLong.restype = WndProcType SetWindowLong.argtypes = [wintypes.HWND, wintypes.INT, WndProcType] GWL_WNDPROC = -4 WM_KEYDOWN = 0x0100 WM_KEYUP = 0x0101 WM_KILLFOCUS = 0x0008 VK_SHIFT = 0x10 VK_LSHIFT = 0xA0 VK_RSHIFT = 0xA1 VK_CONTROL = 0x11 VK_LCONTROL = 0xA2 VK_RCONTROL = 0xA3 #------------------------------------------------------------------------------- class SPCCLRM(object): def __init__(self): self.debug = True if 0 else False self.reset() self.new_editor1_wnd_proc_hook_for_SetWindowLong = WndProcType(self.new_editor1_wnd_proc_hook) self.orig_editor1_wnd_proc = SetWindowLong(editor1.hwnd, GWL_WNDPROC, self.new_editor1_wnd_proc_hook_for_SetWindowLong) self.new_editor2_wnd_proc_hook_for_SetWindowLong = WndProcType(self.new_editor2_wnd_proc_hook) self.orig_editor2_wnd_proc = SetWindowLong(editor2.hwnd, GWL_WNDPROC, self.new_editor2_wnd_proc_hook_for_SetWindowLong) def reset(self): self.waiting_for_lshift_down = self.waiting_for_lctrl_down = self.waiting_for_rshift_down = self.waiting_for_rctrl_down = True self.waiting_for_lshift_up = self.waiting_for_lctrl_up = self.waiting_for_rshift_up = self.waiting_for_rctrl_up = False def key_down(self, key): return (user32.GetAsyncKeyState(key) & 0x8000) != 0 def common_editor_wnd_proc_hook(self, hwnd, msg, wParam, lParam): retval = True editor_num = 1 if hwnd == editor1.hwnd else '2' if msg == WM_KEYDOWN: self.print('editor{e} WM_KEYDOWN wParam={w}/0x{w:X} lParam={l}/0x{l:X}'.format(e=editor_num, w=wParam, l=lParam)) if wParam == VK_SHIFT: if self.key_down(VK_LSHIFT): if self.waiting_for_lshift_down: if not self.waiting_for_lctrl_down: self.waiting_for_lshift_up = self.waiting_for_lctrl_up = True self.waiting_for_lshift_down = False else: # VK_RSHIFT must be down if self.waiting_for_rshift_down: if not self.waiting_for_rctrl_down: self.waiting_for_rshift_up = self.waiting_for_rctrl_up = True self.waiting_for_rshift_down = False elif wParam == VK_CONTROL: if self.key_down(VK_LCONTROL): if self.waiting_for_lctrl_down: if not self.waiting_for_lshift_down: self.waiting_for_lshift_up = self.waiting_for_lctrl_up = True self.waiting_for_lctrl_down = False else: # VK_RCONTROL must be down if self.waiting_for_rctrl_down: if not self.waiting_for_rshift_down: self.waiting_for_rshift_up = self.waiting_for_rctrl_up = True self.waiting_for_rctrl_down = False else: self.reset() #retval = False # set to False if we don't want further processing of this message elif msg == WM_KEYUP: self.print('editor{e} WM_KEYUP wParam={w}/0x{w:X} lParam={l}/0x{l:X}'.format(e=editor_num, w=wParam, l=lParam)) if wParam == VK_SHIFT: if self.waiting_for_lshift_up: if not self.key_down(VK_LSHIFT): if not self.waiting_for_lctrl_up: if self.debug: self.print('LC previously up, now LS up -- set LTR') else: notepad.menuCommand(MENUCOMMAND.EDIT_LTR) self.reset() self.waiting_for_lshift_up = False elif self.waiting_for_rshift_up: if not self.key_down(VK_RSHIFT): if not self.waiting_for_rctrl_up: if self.debug: self.print('RC previously up, now RS up -- set RTL') else: notepad.menuCommand(MENUCOMMAND.EDIT_RTL) self.reset() self.waiting_for_rshift_up = False elif wParam == VK_CONTROL: if self.waiting_for_lctrl_up: if not self.key_down(VK_LCONTROL): if not self.waiting_for_lshift_up: if self.debug: self.print('LS previously up, now LC up -- set LTR') else: notepad.menuCommand(MENUCOMMAND.EDIT_LTR) self.reset() self.waiting_for_lctrl_up = False elif self.waiting_for_rctrl_up: if not self.key_down(VK_RCONTROL): if not self.waiting_for_rshift_up: if self.debug: self.print('RS previously up, now RC up -- set RTL') else: notepad.menuCommand(MENUCOMMAND.EDIT_RTL) self.reset() self.waiting_for_rctrl_up = False else: self.reset() #retval = False # set to False if we don't want further processing of this message elif msg == WM_KILLFOCUS: self.print('editor{e} WM_KILLFOCUS wParam={w}/0x{w:X} lParam={l}/0x{l:X}'.format(e=editor_num, w=wParam, l=lParam)) self.reset() #retval = False # set to False if we don't want further processing of this message return retval def new_editor1_wnd_proc_hook(self, hwnd, msg, wParam, lParam): retval = self.common_editor_wnd_proc_hook(hwnd, msg, wParam, lParam) if retval: retval = self.orig_editor1_wnd_proc(hwnd, msg, wParam, lParam) return retval def new_editor2_wnd_proc_hook(self, hwnd, msg, wParam, lParam): retval = self.common_editor_wnd_proc_hook(hwnd, msg, wParam, lParam) if retval: retval = self.orig_editor2_wnd_proc(hwnd, msg, wParam, lParam) return retval def print(self, *args): if self.debug: #console.show() print('SPCCLRM:', *args) #------------------------------------------------------------------------------- # to run via another file, e.g., startup.py, put these lines (uncommented and unindented) in that file: # import ShiftPlusCtrlChangesLtrRtlMode # spcclrm = ShiftPlusCtrlChangesLtrRtlMode.SPCCLRM() if __name__ == '__main__': SPCCLRM()
-
-