Blockly maintains a registry of keyboard shortcuts that map keys (or key combinations like ctrl-C ) to actions. The registry is prepopulated with a number of shortcuts, such as ctrl-C and meta-C for copy. You can add shortcuts to and delete shortcuts from the registry.
কীবোর্ড শর্টকাট কীভাবে কাজ করে
The shortcut registry contains objects that model keyboard shortcuts. When the user presses a key (or combination of keys), Blockly:
কীটিতে কোন শর্টকাট প্রযোজ্য কিনা তা দেখার জন্য রেজিস্ট্রি পরীক্ষা করে। যদি একাধিক শর্টকাট কী ব্যবহার করে, তাহলে শর্টকাটগুলি নিবন্ধনের বিপরীত ক্রমে চেষ্টা করা হয়। অর্থাৎ, সবচেয়ে সাম্প্রতিক নিবন্ধিত শর্টকাটটি প্রথমে চেষ্টা করা হয়।
Calls the shortcut's
preconditionFnfunction, which determines whether the shortcut applies to the current situation. For example, the copy shortcut applies to blocks but not to the workspace. If the shortcut doesn't apply, Blockly tries the next shortcut in the list, if any.Calls the shortcut's
callbackfunction, which executes the shortcut's action. For example, the copy shortcut makes a copy of the currently focused object, such as a block. If this function returnstrue, processing stops. If it returnsfalse, Blockly tries the next shortcut in the list, if any.
ব্যাপ্তি
একটি Scope অবজেক্ট Blockly কম্পোনেন্টকে শনাক্ত করে যার বর্তমানে ফোকাস আছে। Scope অবজেক্টগুলি preconditionFn এবং callback এ পাস করা হয়, যা এগুলি ব্যবহার করে সিদ্ধান্ত নেয় যে একটি শর্টকাট একটি নির্দিষ্ট কম্পোনেন্টের জন্য প্রযোজ্য কিনা এবং যদি তাই হয়, তাহলে এটি কীভাবে প্রয়োগ করা হবে।
To use a Scope object, use its focusedNode property. This is an object that implements IFocusableNode . This interface is implemented by all Blockly components that the user can focus on, including workspaces, blocks, fields, comments, and your own custom components; for more information, see Focus system .
For example, a preconditionFn might use focusedNode to ensure that a shortcut only applies to blocks.
preconditionFn(workspace, scope) {
return (scope.focusedNode instanceof Blockly.BlockSvg);
}
কীবোর্ড শর্টকাট ইন্টারফেস
Objects in the shortcut registry implement the KeyboardShortcut interface. This contains the following properties.
নাম (প্রয়োজনীয়)
A unique name for the shortcut. This is not shown to users and does not need to be human-readable. It should not be translated.
const logFieldsShortcut = {
name: 'logFields',
// ...
};
preconditionFn (optional)
বর্তমান পরিস্থিতিতে কোন শর্টকাট প্রযোজ্য কিনা তা নির্ধারণ করার জন্য ব্লকলি এই ফাংশনটিকে কল করে। যদি এটি true রিটার্ন করে, তাহলে ব্লকলি callback কল করে। যদি এটি false রিটার্ন করে, তাহলে ব্লকলি এই শর্টকাটটিকে উপেক্ষা করে। উদাহরণস্বরূপ:
const logFieldsShortcut = {
// ...
preconditionFn(workspace, scope) {
// This shortcut only applies to blocks.
return (scope.focusedNode instanceof Blockly.BlockSvg);
},
// ...
};
A shortcut can omit this function if the shortcut always applies (uncommon). Shortcuts should not omit this function and then take action conditionally in callback . Doing so prevents Blockly from doing things like building contextual help menus that show applicable shortcuts.
কলব্যাক (ঐচ্ছিক)
This function executes the action associated with the shortcut. It is called only if preconditionFn returns true or does not exist. Its parameters are:
-
workspace: The currentWorkspaceSvg. -
e: যেEventশর্টকাট শুরু করেছিল। -
shortcut: TheKeyboardShortcutitself. -
scope: TheScopeto which the shortcut applies.
It returns true if it succeeds and false if it fails.
উদাহরণস্বরূপ:
const logFieldsShortcut = {
// ...
callback(workspace, event, shortcut, scope) {
// preconditionFn required focusedNode to be a BlockSvg.
for (input of scope.focusedNode.inputList) {
// Log the values of all named fields. (Label fields usually don't have names.)
for (field of input.fieldRow) {
if (field.name) {
console.log(field.name + ': ' + field.getText());
}
}
}
return true;
},
// ...
};
Although callback is optional, there is generally no reason not to implement it.
কীকোড (ঐচ্ছিক)
An array of keys (or combinations of keys) that activate this shortcut. To identify keys, use the keycodes in Blockly.utils.KeyCodes . For example:
const logFieldsShortcut = {
// ...
keyCodes: [Blockly.utils.KeyCodes.L],
// ...
};
যদি আপনি একটি বিদ্যমান শর্টকাটে অতিরিক্ত কী ম্যাপ করতে চান -- উদাহরণস্বরূপ, আপনি একটি ডিফল্ট শর্টকাটে কী যোগ করতে চান -- তাহলে আপনি Blockly.ShortcutRegistry.registry.addKeyMapping কল করতে পারেন। এটি সাধারণ নয়।
Key combinations
If your keyboard shortcut is activated by a combination of keys, such as holding Control and C simultaneously, create a serialized keycode by calling Blockly.ShortcutRegistry.registry.createSerializedKey :
const ctrlC = Blockly.ShortcutRegistry.registry.createSerializedKey(
Blockly.utils.KeyCodes.C, // Keycode of main key
[Blockly.utils.KeyCodes.CTRL], // Array of modifier keys
);
const copyShortcut = {
// ...
keyCodes: [ctrlC], // Use the serialized keycode
// ...
};
নিয়ন্ত্রণ এবং মেটা
On Windows, many shortcuts are activated with the Control key. On Mac, these keyboard shortcuts use the Command key instead, which is recognized as the META keycode. To support both operating systems, register your shortcuts with both the CTRL keycode and the META keycode.
const ctrlC = Blockly.ShortcutRegistry.registry.createSerializedKey(
Blockly.utils.KeyCodes.C,
[Blockly.utils.KeyCodes.CTRL],
);
const metaC = Blockly.ShortcutRegistry.registry.createSerializedKey(
Blockly.utils.KeyCodes.C,
[Blockly.utils.KeyCodes.META],
);
const copyShortcut = {
// ...
keyCodes: [ctrlC, metaC],
// ...
};
Implementation note
Blockly's keyboard event handlers use the keycode property of KeyboardEvent even though it is deprecated.
allowCollision (optional)
ডিফল্টরূপে, আপনি একটি প্রদত্ত কী বা কী সংমিশ্রণের জন্য কেবল একটি শর্টকাট নিবন্ধন করতে পারবেন। এই বৈশিষ্ট্যটিকে true হিসাবে সেট করলে আপনি একটি কী (বা কী সংমিশ্রণ) নিবন্ধন করতে পারবেন, এমনকি যদি একই কী (বা কী সংমিশ্রণ) সহ একটি শর্টকাট ইতিমধ্যেই নিবন্ধিত হয়ে থাকে।
মনে রাখবেন যে এই বৈশিষ্ট্যটি শুধুমাত্র এই শর্টকাটটি নিবন্ধন করার সময় প্রযোজ্য। এটি অন্যান্য শর্টকাটগুলিকে একই কী (অথবা কী সংমিশ্রণ) ব্যবহার করতে বাধা দেয় না। এগুলি নিবন্ধিত করা যাবে কিনা তা তাদের allowCollision সম্পত্তির মানের উপর নির্ভর করে।
একটি প্রদত্ত কী বা কী সংমিশ্রণের জন্য কতগুলি শর্টকাট নিবন্ধিত হোক না কেন, সর্বাধিক একটি সফলভাবে কার্যকর করা হবে। শর্টকাটগুলি নিবন্ধনের বিপরীত ক্রমে চেষ্টা করা হয় (শেষ নিবন্ধিত থেকে প্রথম নিবন্ধিত পর্যন্ত)। তাদের মধ্যে একটি তাদের কলব্যাক থেকে true ফেরত দেওয়ার পরে, অন্য কোনও শর্টকাট চেষ্টা করা হয় না।
metadata (optional)
This is an arbitrary object containing additional information. It is available to callback through the shortcut parameter.
Add, delete, and modify shortcuts
To add a new keyboard shortcut, call Blockly.ShortcutRegistry.registry.register :
Blockly.ShortcutRegistry.registry.register(logFieldsShortcut);
এই ফাংশনটিতে একটি দ্বিতীয় প্যারামিটার ( allowOverrides ) রয়েছে যা আপনাকে একটি বিদ্যমান শর্টকাটকে আপনার শর্টকাটের মতো একই নামের সাথে প্রতিস্থাপন করতে দেয়। মনে রাখবেন যে এটি KeyboardShortcut.allowCollision থেকে আলাদা, যা আপনাকে একটি ভিন্ন নামের একটি শর্টকাট যোগ করতে দেয় কিন্তু বিদ্যমান শর্টকাটের মতো একই কী বা কী সমন্বয় ব্যবহার করে।
To delete a keyboard shortcut, call Blockly.ShortcutRegistry.registry.unregister and pass the name of the shortcut:
Blockly.ShortcutRegistry.registry.unregister('logFields');
You cannot modify a keyboard shortcut in place. Instead, you need to delete the existing shortcut and add a new one. For example:
// Get the existing shortcut. getRegistry returns an object keyed by shortcut name.
const allShortcuts = Blockly.ShortcutRegistry.registry.getRegistry();
const modLogFieldsShortcut = allShortcuts[logFieldsShortcut.name];
// Apply the shortcut only to math blocks,
modLogFieldsShortcut.preconditionFn = function (workspace, scope) {
return (scope.focusedNode instanceof Blockly.BlockSvg &&
scope.focusedNode.type.startsWith('math_'));
}
// Delete the existing shortcut and add the modified shortcut.
Blockly.ShortcutRegistry.registry.unregister(logFieldsShortcut.name);
Blockly.ShortcutRegistry.registry.register(modLogFieldsShortcut);
Default shortcuts
শর্টকাট রেজিস্ট্রিতে বেশ কিছু শর্টকাট আগে থেকেই থাকে। আপনি এগুলি https://github.com/RaspberryPiFoundation/blockly/blob/master/core/shortcut_items.ts এ খুঁজে পেতে পারেন। শর্টকাটগুলি registerXxxx ফাংশনে সংজ্ঞায়িত করা হয়েছে।
Keyboard navigation shortcuts
কীবোর্ড নেভিগেশন প্লাগইনে এমন শর্টকাট রয়েছে যা ব্যবহারকারীদের কীবোর্ড দিয়ে ব্লকলি নেভিগেট করতে দেয়, যেমন তীরচিহ্ন ব্যবহার করে। কীবোর্ড নেভিগেশন এমন ব্যবহারকারীদের জন্য অপরিহার্য যারা মাউস ব্যবহার করতে পারেন না, যেমন মোটর বা দৃষ্টি প্রতিবন্ধী ব্যক্তিরা। এটি এমন পাওয়ার ব্যবহারকারীদের জন্যও কার্যকর যারা দক্ষতার জন্য কীবোর্ড শর্টকাট ব্যবহার করতে চান।